  | | | Custom Objects and Classes for Scripting | Custom Objects and Classes for Scripting 2005-03-26 - By Bernard Lebel
Back Hi Brad,
Not sure if it will help, but Michael Isner has a bunch of script on XSI Base in our last Talk With The Pros workshop. His examples make sure of custom objects, and are in JScript :-D
http://www.xsibase.com/forum/index.php?board=26;action=display;threadid=16336 ;start=45
You may want to check the ExpressionUICurve.zip file in his first post on the above page.
That said, I think what you are referring to are compiled dlls. Personally, since I don't have a clue about C++ and compiling other than what it is used for, all I can say is that you don't need compiled code to call custom objects. I have a large set of handlers that are basically Python module, I just need to call the functions in the modules. I can also turn anything into an object by writing a class statement and instantiating this class. Example:
Part of a module named LT_ligthStats.py:
import string from win32com.client import constants as c
class Ls: # Define initial state of class object def __init__( self, oLight ): self.Light = oLight self.BasicType = self.Light.activeprimitive.parameters( 'Type' ).value
# advLightID custom property self.HasAdvancedLightIDProp = self.eval_HasAdvancedLightIDProp() # Light instancing self.InstancingStatus = 'NA' if self.HasAdvancedLightIDProp == True: # Call function to get instancing status self.InstancingStatus = self.eval_InstancingStatus()
# AreaTransform custom property self.HasAreaTransforms = self.eval_HasAreaTransforms()
The self.eval_Has...() you see above are calls to the methods of the same class (hence the "self" thing).
Then in my XSI script, I first import the module, then instantiate the Ls class with an argument (the class builds statistics for a light), then access its attributes. The values persist only during the XSI session.
# Import module import LT_lightStats
# Get selected light oLight = xsi.selection(0)
# Create instance of Ls class from module, pass it light ls = LT_lightStats.Ls( oLight )
# Print class instance attribute xsi.logmessage( ls.HasAreaTransforms )
# Yet again if ls.HasAreaTransform == True: xsi.logmessage( 'yeah!' ) else: xsi.logmessage( 'no' )
Later I can change the attribute values if I want, or add attributes.
# Set my own value for attribute ls.HasAreaTransform = False
# Add custom attribute to class instance ls.AnotherAttribute = 'another attribute!'
Hope this helps Bernard
Brad Friedman wrote: > Hi, > > I just read the blog entry, "Why Create Custom Objects and Classes for > Scripting in XSI?" over at CGSoup. > > And it solved about 5-10 design issues I was having with my toolkit :) > THANK YOU! > > But I have a few questions if anyone can answer. > > in the example code given, the object is retrieved with the command: > > [code] > set gt = GUITools(0) > [/code] > > which makes sense. But I was wondering about the instantiation of the > object itself. First of all, what are some of the best standards and > practices of creating objects in jscript? My understanding is that > there are a couple of ways to do it and I was wondering if anyone has > any reason why one way in particular is better for XSI. > > I intend to roll an object as a utility library of functions (as > suggested as one possible use in the blog entry). If I'm understanding > the example, I think thats what GUITools is doing as well. Am I to > understand that the object is instantiated every time the "GUITools" > command is called? Or is it cache'ing it somewhere in global memory the > first time and just passing the same instance on subsequent calls? Or > is the instantiation so cheap, it doesn't matter that you instantiate it > in every function you use it in? Is there a good place to toss an > object where it will persist for the remainder of the given XSI > session? Or is that foolhearty? > > thanks, > -brad > --- > Unsubscribe? Mail Majordomo@(protected) with the following text in body: > unsubscribe xsi > > >
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |