The following examples are provided in this section:
• Example: Triggering OnChanged() by the user changing a value
• Example: Disabling parameters based on conditions
• Example: Getting the name of the inspected preset
• Example: Displaying a message when the user switches tabs
Example: Triggering OnChanged() by the user changing a value
When a user sets (or clears) the check box labelled "Use Feature A?", then this OnChanged event handler is triggered, making the following changes:
• Enables (or disables) the parameters for Parameter A.
• Disables (or enables) the mutually exclusive Parameter B.
PropertySet "OnChangeDemo_pset"
{
Parameter "out" output
{
GUID = "{248FCEFE-DBA6-412A-9A8F-17A96D97F1E3}";
Type = color;
}
Parameter "ParameterA" input
{
GUID = "{379493F5-B9E4-4E09-92DE-923C65DCC119}";
Type = scalar;
Value = 0.0;
}
Parameter "ParameterB" input
{
GUID = "{3F61E7BD-AEA5-41D1-8D41-8B7BD6976847}";
Type = scalar;
Value = 0.0;
}
Parameter "UseParameterA" input
{
GUID = "{D30A583A-ED9C-4065-85F8-436401DD556A}";
Type = boolean;
Value = on;
}
}
Defaults
{
UseParameterA
{
Name = "Use Feature A?";
}
}
Layout "Default"
{
ParameterA;
ParameterB;
Group "Usage"
{
UseParameterA;
}
}
BeginScript
' Notice how we access the parameter value via the default Parameter.Value
' property (see How Parameters Behave in The Logic Section)
Sub UseParameterA_OnChanged()
ParameterA.Enable UseParameterA
ParameterB.Enable Not UseParameterA
End Sub
' To properly set the initial enable states (as the property page opens),
' the OnInit event handler must call the UseParameterA_OnChanged event handler.
Sub OnInit()
ParameterA.Enable false
UseParameterA_OnChanged
End Sub
EndScriptExample: Disabling parameters based on conditions
Suppose you want to implement some simple logic for the controls on a property page. For example, based on the value of one control, you may want to hide or disable other controls.
You can update the UI state of properties using a Logic section in a SPDL file. A Logic section contains a script that is executed whenever a property value changes.
For example, suppose you have three parameters:
• UseLight (boolean)
• LightDistance (scalar)
• LightSpread (scalar)
Here’s how you might control the UI based on certain property values:
PropertySet "DisablingDemo_pset"
{
Parameter "out" output
{
GUID = "{248FCEFE-DBA6-412A-9A8F-17A96D97F1E3}";
Type = color;
}
Parameter "LightDistance" input
{
GUID = "{379493F5-B9E4-4E09-92DE-923C65DCC119}";
Type = scalar;
Value = 1.0;
}
Parameter "LightSpread" input
{
GUID = "{3F61E7BD-AEA5-41D1-8D41-8B7BD6976847}";
Type = scalar;
Value = 1.0;
}
Parameter "LightAngle" input
{
GUID = "{62B67913-8FB7-485F-BF41-128B645735FB}";
Type = scalar;
Value = 0.0;
}
Parameter "UseLight" input
{
GUID = "{D30A583A-ED9C-4065-85F8-436401DD556A}";
Type = boolean;
Value = on;
}
}
BeginScript
' Notice how we access the parameter values via the default Parameter.Value
' property (see How Parameters Behave in The Logic Section)
Sub UseLight_OnChanged()
LightDistance.Enable( UseLight )
LightSpread.Enable( UseLight )
LightAngle.Enable( UseLight )
End Sub
Sub LightDistance_OnChanged()
If LightDistance > 55.0 Then
LightAngle = LightSpread / 3.14
End If
Application.LogMessage "LightAngle = " & LightAngle
End Sub
Sub LightSpread_OnChanged()
If LightSpread > 35.0 Then
LightAngle = LightSpread / 2
End If
Application.LogMessage "LightAngle = " & LightAngle
End Sub
' Hide the LightAngle parameter
Sub OnInit()
LightAngle.Show false
End Sub
EndScriptExample: Getting the name of the inspected preset
The Logic section has access to the PPG.Inspected property. It returns a collection of property page objects being expected. Normally this collection will contain only one object (a CustomProperty); however, the collection will contain more than one object if the page is in multi-edit mode.
This example displays the name(s) of the inspected object(s) when the user clicks the WhoAmI button.
BeginScript
Sub OnInit()
' PPG is a object that always available in the event handlers
Application.LogMessage "Init PPG for " & PPG.Inspected.GetAsText & " Objects"
' INFO : Init PPG for Sources.Materials.DefaultLib.Scene_Material.Phong.InspectObjectsDemo Objects
End Sub
Sub WhoAmI_OnClicked()
Application.LogMessage "I am " & PPG.Inspected.GetAsText
' INFO : I am Sources.Materials.DefaultLib.Scene_Material.Phong.InspectObjectsDemo
End Sub
EndScriptExample: Displaying a message when the user switches tabs
This example demonstrates how to trap the OnTab event. As with other event handlers, the property’s parameters and PPG object are available, so you more than just messaging logging is available if desired.
Layout "Default"
{
Tab "Greasy"
{
' ...
}
Tab "Gooey"
{
' ...
}
}
BeginScript
Sub Greasy_OnTab()
Application.LogMessage "Factoring greasyness..."
End Sub
Sub Gooey_OnTab()
Application.LogMessage "Factoring gooeyness..."
End Sub
EndScript
Autodesk Softimage v7.5