Object Hierarchy | Related C++ Class: PPGEventContext
v4.0
Represents an instance of a Property Page. This object can be
manipulated within the event handling script code associated with a
PPGLayout. (This event handling code
is often called "SPDL logic" because in previous versions it could
only be specified by putting script code directly in a spdl file.)
This object is available to logic code as a global variable called
"PPG". (For the purposes of backward compatibility it is also
available via the global variable "PSet". It is also for reasons of
backward compatibility that this object does not derive from
Context and is available as a global
variable rather than being passed as an argument to the callback
routines).
There are two ways a Property Page can inspect multiple objects. In
the first case, where the objects are of different types, there
will actually be separate Property Page objects displayed within
the same frame. In the second case, where the objects have the same
type, multi-edit mode is used and a single instance of the PPG
object may actually represent multiple objects. This is why the
property PPG.Inspected returns an
array rather than a single object.
This object provides shortcuts for direct access to the Parameters of the inspected object. For
example, if a Property Page has a parameter named x then
"PPG.x.Value = 10" is the VBScript code to change the value. In the
case of multi-edit mode, this technique will only modify the first
inspected object.
Note: The equivalent object in the C++ API is called
PPGEventContext.
/*
This example shows how to build an extremely dynamic Custom Property using
the PPG object. It appears in two parts:
* PART ONE writes the implementation to disk, loads it in Softimage, and
then displays the property editor.
* PART TWO is the code that implements the custom property
Not only does the layout change but the actual underlying parameters are
rebuilt each time the Property Page is shown.
Once this plugin is installed you can apply an instance of the custom
property via the Property Menu on the left side of the screen. Then
each time you inspect the custom property it will regenerate its UI
so that there is a check box for each X3DObject parented under the scene
root. You can pick which ones to select and then click apply.
Normally a feature like this would probably be implemented as a custom
command that pops up a temporary, modal custom property which is deleted
after the fact. However for the purpose of this example the custom
property remains in the scene for use whenever the user wants to change
selection.
(This example was implemented by using the Custom Property wizard to
generate the initial plugin and then editing the code to add the dynamic
behavior)
*/
NewScene( null, false );
// ------------------------------------------------------------
//
// PART ONE: Save Implementation to Disk and Open PPG
//
var filename = XSIUtils.BuildPath( Application.InstallationPath(siUserPath),
"Application", "Plugins", "DynParamDemo.js" );
// Write the contents of the Implementation functions below to DynParamDemo.js
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var ts = fso.CreateTextFile( filename, true );
ts.Write( XSILoadPlugin.toString() + "\n\n" );
ts.Write( DynParamDemo_Define.toString() + "\n\n" );
ts.Write( DynParamDemo_DefineLayout.toString() + "\n\n" );
ts.Write( DynParamDemo_OnInit.toString() + "\n\n" );
ts.Write( DynParamDemo_Apply_OnClicked.toString() );
ts.Close();
// Load the plugin
Application.LoadPlugin( filename );
// Instantiate the custom property and display its property page
var oCustomProperty = Application.ActiveSceneRoot.AddProperty( "DynParamDemo" );
InspectObj( oCustomProperty );
// ------------------------------------------------------------
//
// PART TWO: PPG Implementation
//
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Softimage";
in_reg.Name = "DynParamDemoPlugin";
in_reg.Major = 1;
in_reg.Minor = 1;
in_reg.RegisterProperty( "DynParamDemo" );
return true;
}
function DynParamDemo_Define( io_Context )
{
// No parameters are added here because we want the
// data to be dynamic, see DynParamDemo_OnInit
}
function DynParamDemo_DefineLayout( io_Context )
{
// Do nothing here because we want a dynamic layout.
// The work is done inside DynParamDemo_OnInit instead.
}
function DynParamDemo_OnInit()
{
// This example doesn't make sense in the case
// of selection of more than one instance of the custom
// property at a time, so we only look at the first inspected
var oCustomProperty = PPG.Inspected.Item(0);
// Remove any existing parameters
for ( var i=oCustomProperty.Parameters.Count-1; i>=0; i-- ) {
oCustomProperty.RemoveParameter( oCustomProperty.Parameters.Item(i) );
}
var oLayout = PPG.PPGLayout;
oLayout.Clear();
var oSceneChildren = Application.ActiveSceneRoot.Children;
for ( var j=0; j<oSceneChildren.Count; j++ ) {
var oChild = oSceneChildren.Item(j);
// Add a boolean parameter to represent this object
oCustomProperty.AddParameter2( oChild.Name, siBool, false,
null, null, null, null, 0, siPersistable );
// Put this in the layout
oLayout.AddItem( oChild.Name, "Select " + oChild.Name );
}
oLayout.AddButton( "Apply" );
PPG.Refresh();
}
function DynParamDemo_Apply_OnClicked()
{
DeselectAll(); // Call Softimage Command
var oCustomProperty = PPG.Inspected.Item(0);
for ( var j=0; j<oCustomProperty.Parameters.Count; j++ ) {
var oParam = oCustomProperty.Parameters.Item(j);
if ( oParam.Value == true ) {
// We used a naming sceme for the parameters that matches the object
AddToSelection( oParam.Name ); // Call Softimage Command
}
}
}
|