PPG callbacks and variable scope


The scope of variable b is this snippet. That is, the identifier b exists and has the value 1 only while this snippet is running. After that, it doesn’t exist unless some other code defines it.

Consequently, the OnClicked callback is going to fail with a ‘b’ is undefined error.

var myPset = ActiveSceneRoot.AddProperty("CustomProperty",false,"Mytest");
var myLayout = myPset.PPGLayout;

var b = 1;

function a_OnClicked(){
	LogMessage( b );	
}

myLayout.AddRow()
myLayout.AddButton("a","button");
myLayout.EndRow() 

myLayout.Logic=OnInit.toString() +  a_OnClicked.toString();
myLayout.Language = "JScript" ;

InspectObj(myPset);

The way it works is that Softimage creates a new instance of the JScript ActiveX scripting engine each time it needs to execute some fragment of code. So, the above snippet runs in one instances of the scripting engine (which is destroyed after the code is executed). Then later, when the button is clicked, the OnClicked callback runs in a new and different instances of the scripting engine. And that new instance of the scripting engine, there is no variable named b.

One way around this would be to add b as a parameter:

var myPset=ActiveSceneRoot.AddProperty("CustomProperty",false,"Mytest");
var b =	myPset.AddParameter2("b",siInt4,1,0,100,0,100,siClassifUnknown,siPersistable | siKeyable);

var myLayout=myPset.PPGLayout;

myLayout.AddRow()
myLayout.AddButton("a","button");
myLayout.EndRow() 
myLayout.Logic=OnInit.toString() +  a_OnClicked.toString();
myLayout.Language = "JScript" ;

InspectObj(myPset);

function a_OnClicked(){
	LogMessage(PPG.b);	
}

Another way would be to use a LogicFile, something like this:

// LogicFile for an on-the-fly custom property
var b = 1;
var c = -1;
function OnInit() {
	LogMessage( "OnInit" );
	c = 99;
}
function a_OnClicked(){
	LogMessage( b );	
	LogMessage( c );
}

Then your property would work like this:

var myPset=ActiveSceneRoot.AddProperty("CustomProperty",false,"Mytest");
var myLayout=myPset.PPGLayout;

myLayout.AddRow()
myLayout.AddButton("a","button");
myLayout.SetAttribute( siUILogicFile, "\\some\\path\\LogicFile.js" );

myLayout.EndRow() 
myLayout.Language = "JScript" ;

InspectObj(myPset);

And this would give the following output:

// INFO : OnInit
// INFO : 1
// INFO : 99

Fun with PPG shortcut keys


You can use the PageUp and PageDown keys to move back and forward through the history of recently inspected nodes.
PPG_Back_PageUp
PPG_Forward_PageDown

If you right-click one of those arrows, you can see the history list of inspected nodes, and select a specific node to inspect:
PPG_History

If there’s no property page open at the moment, pressing PageUp (or PageDown) will open a property page and load the most recently inspected node.

Here’s a related TD Survival video on PageUp (and some other handy shortcut keys):

Shortcuts and default properties for custom parameters


Custom properties and the PPG object provide shortcuts for direct access to parameters.

For custom properties, that means you can type the shortcut oProp.SomeParam instead of oProp.Parameters(“SomeParam”). Note that that in this case, the default property is Name: if you print oProp.SomeParam, you get the name of the parameter.

from win32com.client import constants as C
si = Application

p = si.ActiveProject.ActiveScene.Root.AddCustomProperty( "Test" )
x = p.AddParameter2("X",C.siString,"a;b;c;d",None,None,None,None,C.siClassifUnknown,C.siPersistable)

print p.X
print p.X.IsEqualTo( p.Parameters("X") )
print x.IsEqualTo( p.X )

# Test.X
# True
# True

For the PPG object, the shortcut is even more of a convenience. To access a parameter named “Param”, you can type PPG.Param instead of PPG.Inspected(0).Param. And when you use the PPG.Param shortcut, the default property is Value.

So you can do this:

PPG.Param = 'hello;world'

There’s no need to type “PPG.Param.Value”, unless you’re doing something like this:

list = PPG.Param.Value.split(';')