Now that you know the purpose of the Expression() object, I’m going to show some examples. I hope you will find it easier and more elegant than the classic string concatenation (and also I hate the word “konkatenation”).
First example : We really need to clamp a null position inside a cube to create the best character rig ever done (simple as that).
There is no built in clamp function in XSI (I know, it sucks…). Instead we can use a conditional expression or a combination of MIN and MAX expressions. On top of that, you add the script concatenation and it will looks like a very ugly thing. Fortunately, the brand new Expression object is there to save your mental health ! Lets code now :
#First you import the xsi_expr module and get the Expression class
#(I presum that you already know a way to set a path to a module from xsi)
import xsi_expr
from xsi_expr import Expression
#Then the ‘exotic’ XSI python things
xsi = Application
xsilog=xsi.LogMessage
#Lets build a simple implicit cube and a null
cube = xsi.ActiveSceneRoot.AddGeometry(“cube”)
nullInsideCube = xsi.ActiveSceneRoot.AddNull(‘inside_cube’)
#Then the null x, y z positions parameters
nullPosx = nullInsideCube.posx
nullPosy = nullInsideCube.posy
nullPosz = nullInsideCube.posz
#Here is the first Expression Object to get the cube limits from its length.
cubeLimitMax=Expression(cube.length)
cubeLimitMax.div(2)
#Then we create the min limit from the max limit like this:
cubeLimitMin=Expression()
cubeLimitMin.sub(cubeLimitMax.Value)
#Then we can create the expressions objects for the position x, y ,z of the null.
posInCubeX = Expression()
posInCubeX.clamp(nullPosx, cubeLimitMin.Value, cubeLimitMax.Value)
posInCubeY = Expression()
posInCubeY.clamp(nullPosy, cubeLimitMin.Value, cubeLimitMax.Value)
posInCubeZ = Expression()
posInCubeZ.clamp(nullPosz, cubeLimitMin.Value, cubeLimitMax.Value)
#And finally apply the expressions to the parameters
nullPosx.AddExpression(posInCubeX.Value)
nullPosy.AddExpression(posInCubeY.Value)
nullPosz.AddExpression(posInCubeZ.Value)
#xsiShow method like this :
posInCubeX.xsiShow()
#MIN( MAX( inside_cube.kine.local.posx, - cube.cube.length / 2 )
#, cube.cube.length / 2 )
#xsilog( posInCubeX.Value)
…
Here is an other exemple just to show how to use the pow and fit methods :
import xsi_expr
from xsi_expr import Expression
xsi = Application
#Lets build two nulls
xsilog( Brotz.Value )
# INFO :
#cond( A.kine.local.rotz<0, (A.kine.local.rotz/0)
#*0, (A.kine.local.rotz/360)*90 )
If you are not exhausted by this post, you can try the module on your own here.
Happy scripting !
Cheers
Guillaume Laforge
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.