#WIP !!! #File could be updated regularly on my website without warning ! import win32com xsi = win32com.client.Dispatch( 'XSI.Application' ).Application class Expression: ''' Feel free to add more XSI expressions to the Expression class ! Then you can send the file to guillaume.laforge.3d@gmail.com - Those methodes are the same than XSI expressions : ctr_dist , abs, pow, at_frame, exp. - Those methodes are a combination of several XSI expressions : clamp(XSI parameter, mini=1, maxi=0) fit(XSI parameter, oldmin, oldmax, newmin=0, newmax=1) You can use the add, sub, mul and div methods to insert an operator (+ ,- ,* ,/) between two xsi parameter objects in order to get a valid xsi expression. examples : myExpression = Expression(xsi parameter) -> Create an Expression object with the xsi parameter. myExpression.Value -> To get the fullName. Ex : null.Kinematics.Local.posx myExpression.add(xsi parameter 2) -> insert "+" between the two parameters like this : null.Kinematics.Local.posx + null.Kinematics.Local.posy myExpression.show() -> print the Expression value from a Python Shell. myExpression.xsiShow() -> print the Expression value from the xsi script log. myExpression.text(a string object, 'end') -> insert a string after the Expression value. Default Value : before the Expression value myExpression.par() -> enclose the expression between parentheses : ( null.Kinematics.Local.posx + null.Kinematics.Local.posy ) ''' def __init__(self, parm=''): self.Value = str(parm) def set(self, parm): self.Value = str(parm) #Math Operations def add(self, *args): for arg in enumerate(args): self.Value+=' + '+str(arg[1]) def sub(self, *args): for arg in enumerate(args): self.Value+=' - '+str(arg[1]) def mul(self, *args): for arg in enumerate(args): self.Value+=' * '+str(arg[1]) def div(self, *args): for arg in enumerate(args): self.Value+=' / '+str(arg[1]) def par(self): self.Value = ' ( '+self.Value+' ) ' #Some 'standard' XSI expressions def ctr_dist(self, obj1, obj2): self.Value = 'ctr_dist( '+str(obj1)+'. , '+str(obj2)+'. )' def abs(self): self.Value = 'abs('+self.Value+')' def at_frame( self, frame, parm): self.Value = 'at_frame( Fc - '+str(frame)+','+str(parm)+')' def pow( self, parm1 , power=2 ): self.Value = 'pow( '+str(parm1)+' , '+str(power)+' )' def exp( self, parm1 ): self.Value = 'exp( '+str(parm1)+' )' def cond( self, cond , true_expr , false_expr ): self.Value = 'cond( '+str(cond)+' , '+str(true_expr)+' , '+str(false_expr)+' )' #From mixing standard XSI expression def clamp(self, parm, mini=1, maxi=0): self.Value = 'MIN( MAX( '+str(parm)+', '+str(mini)+' ), '+str(maxi)+' )' def fit(self, parm, oldmin, oldmax, newmin=0, newmax=1): self.Value = 'cond( '+str(parm)+'<0, ('+str(parm)+'/'+str(oldmin)+')*'+str(newin)+', ('+str(parm)+'/'+str(oldmax)+')*'+str(newmax)+' )' #Utils def show(self): print self.Value def text(self, text='', pos='start'): if pos =='start': self.Value= text+self.Value else: self.Value = self.Value+text #To Log the Expression object value def xsiShow(self): xsi.LogMessage(self.Value) #A quick way to see the doc from XSI def xsiDoc(self): xsi.LogMessage(self.__doc__)