<script >Python and the PPG global variable? 2005-04-22 - By Bernard Lebel
Back Hi Nick,
Here is an example of a ppg item in Python:
# Create custom pset oProp = xsi.activesceneroot.addproperty( 'CustomProperty', False, 'ColorPicker' )
# Create color parameters oProp.addparameter3( 'red', c.siDouble ) oProp.addparameter3( 'green', c.siDouble ) oProp.addparameter3( 'blue', c.siDouble ) oProp.addparameter3( 'alpha', c.siDouble )
# Provide layout to pset oLayout = oProp.ppglayout
# Add widget oColor = oLayout.addcolor( 'red', 'red', True ) oColor.setattribute( 'NoLabel', True )
Hope this helps Bernard
Bernard Lebel wrote:
>Is PPG indeed defined somewhere? If so, where? > >Perhaps you are running into a scope problem, wich is critical in >Python. Keep in mind that a name assigned on the wrong scope will >prevent it from being usable in other scopes. >For instance, if you run a command that assigns a name a the top level >(a global for the entire script), this global will not be accessible >outside this file unless you import the file as a module and then >fetch the variable by name qualification (ie: myvariable = >modulename.variablename). > >Normally functions inside a module can access all global names from >that same module, but not from other functions, unless all these >functions are nested into another function and the name is assigned in >that one. The only way to make a name global from a function is to >declare it first as global (with the global statement), then assign it >to a value. > > >Cheers >Bernard > > >On 4/22/05, Nick <nick.petit@(protected)> wrote: > > >>I haven't seen any docs or examples of creating dynamic ppgs done in >>Python but I'm sure it must be feasable... so far I can't seem to get >>the PPG global variable to work with the OnChange callback... I'm >>probably doing this entirely wrong as I'm still fumbling around in the >>dark, but this works in jscript and in vbs but I can't seem to make it >>work in python... >> >>olayout.Logic = str(OnInit()) + \ >> str(Cons_OnChanged()) >> >># then I define my functions >> >>def OnInit(opset): >> olayout = PPG.PPGLayout >> >>This keeps on returning this error: >> >>#ERROR : Traceback (most recent call last): >># File "<Script Block >", line 100, in ? >># PPGCreator() >># File "<Script Block >", line 38, in PPGCreator >># olayout.Logic = str(OnInit(opset)) + str(Cons_OnChanged(opset)) >># File "<Script Block >", line 41, in OnInit >># olayout = PPG.PPGLayout >>#NameError: global name 'PPG' is not defined >># - [line 41] >> >>I can hack it in a very fugly way so it will work on init by passing >>the functions the actual custom prop object as a variable, but after >>it's been created this variable no longer exists in the logic section >>and I'd rather not get it using a Dictionary.GetObject as it's just >>not reliable enough. If someone could shed some light on where I've >>gone wrong that would be really appreciated... :) >> >>Cheers! >>Nick. >> >>--- >>Unsubscribe? Mail Majordomo@(protected) with the following text in body: >>unsubscribe xsi >> >> >> > > >
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|