Creating Expressions

 
 
 

Expressions can be created using scripting commands, the Parameter.AddExpression or Parameter::AddExpression method. The SetExpr command substitutes an Expression or Expression object for the specified parameter's value by using an expression function (see Expression Reference for more information on available expression functions).

Tip

The AddExpr command basically does the same thing as the SetExpr command, but it also displays the new expression in the Expression Editor.

Python Example: Setting an Expression with the SetExpr Command

This is the above example written in Python:

from win32com.client import constants as c
n = Application.ActiveSceneRoot.AddNull( "Null4Expr" )
params = n.posx.FullName+","+n.posy.FullName+","+n.posz.FullName
Application.SetExpr( params, "RAND(17,2,7)" )
Note

The thread of this example continues with accessing the expression in Python Example: Using the GetSource Command, in which the siSourceType enum is used (which is why the constants module was imported).

JScript Example: Setting an Expression with the Parameter.AddExpression Method

Applying the random expression produces a kind of a buzzing effect:

var n = Application.ActiveSceneRoot.AddNull( "Null4Expr" );
n.posx.AddExpression( "RAND(17,2,7)" );
n.posy.AddExpression( "RAND(17,2,7)" );
n.posz.AddExpression( "RAND(17,2,7)" );
Note

The thread of this example continues with accessing the expression in JScript Example: Using the Source Property.

C++ API Example: Setting an Expression with the Parameter::AddExpression Member Function

The following snippet is the C++ API equivalent of the previous JScript example:

// Setup
Application app = Application();
Model root = app.GetActiveSceneRoot();
Null n; root.AddNull( L"Null4Expr", n );

// Get Parameters for names
Parameter posx = n.GetParameter(L"posx");
Parameter posy = n.GetParameter(L"posy");
Parameter posz = n.GetParameter(L"posz");

// Set the expression
posx.AddExpression( L"RAND(17,2,7)" );
posy.AddExpression( L"RAND(17,2,7)" );
posz.AddExpression( L"RAND(17,2,7)" );
Note

The thread of this example continues with accessing the expression in C++ Example: Using the GetSource Member.