Yes it is ugly,
Some time ago somebody asked on the list making trees on geo to
manipulate the transforms when the geo was reading a cache file. I did
some quick script example. Maybe you can find this a good start:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import functools
from win32com.client import constants as c
from win32com.client import Dispatch
xsi = Dispatch('XSI.Application').Application
log = xsi.LogMessage
MSG = XSIUIToolkit.MsgBox
# Temporarily Disable Log (Used as a decoarator)
def disableLog():
prefDict = {"scripting.cmdlog": False} # more key - value pairs can
be added to this dictionary ex: "interaction.autoinspect": False
def outer(func):
@functools.wraps(func)
def inner(*args, **kwargs):
# Get pref values
tmpPrefs = {}
for k, v in prefDict.iteritems():
tmpPrefs[k] = xsi.GetValue("preferences." + k)
xsi.SetValue("preferences." + k, v, "")
try:
# Run original function
return func(*args, **kwargs)
finally:
# restore pref values
for k, v in tmpPrefs.iteritems():
xsi.SetValue("preferences." + k, v, "")
return inner
return outer
def _moveToFirstFrame():
inFrame = xsi.GetValue('PlayControl.In')
msgStr = ""
msgStr += "Do you want to move to first frame before creating \n"
msgStr += "the manipulator null ?"
if MSG(msgStr, c.siMsgYesNo | c.siMsgQuestion, "MOVE TO FIRST FRAME
?")==6:
xsi.SetValue('PlayControl.Current', inFrame)
def _centerNullOnGeo(inNull, inGeo):
c = xsi.GetBBox(inGeo, True)
inNull.Kinematics.Global.Parameters('posx').Value = (c(
"UpperBoundX" ) + c( "LowerBoundX" )) / 2
inNull.Kinematics.Global.Parameters('posy').Value = (c(
"UpperBoundY" ) + c( "LowerBoundY" )) / 2
inNull.Kinematics.Global.Parameters('posz').Value = (c(
"UpperBoundZ" ) + c( "LowerBoundZ" )) / 2
def _createTree(inGeo):
# Create Manipulator Null and ICE Tree on it
manipulatorNull = xsi.ActiveSceneRoot.AddNull('manipulator_%s' %
inGeo.FullName)
_centerNullOnGeo(manipulatorNull, inGeo)
tree = xsi.ApplyOp( "ICETree", manipulatorNull)
getDataManipulatorNode = xsi.AddICENode('GetDataNode', tree)
getDataManipulatorNode.Parameters(0).Value = manipulatorNull.FullName
# Create Get Data Kine Global for Manipulator Null
getDataManipulatorKineGlobalNode = xsi.AddICENode('GetDataNode', tree)
xsi.SetValue("%s.reference" % getDataManipulatorKineGlobalNode,
"kine.global")
inPort = getDataManipulatorKineGlobalNode.GetPortFromName('InName')
outPort = getDataManipulatorNode.GetPortFromName('outName')
xsi.ConnectICENodes(inPort,outPort)
# Create GEo Node and its Kine Global Node
getDataNodeGeo = xsi.AddICENode('GetDataNode', tree)
getDataNodeGeo.Parameters(0).Value = inGeo.FullName
getDataNodeKineGlobal = xsi.AddICENode('GetDataNode', tree)
xsi.SetValue("%s.reference" % getDataNodeKineGlobal, "kine.global")
inPort = getDataNodeKineGlobal.GetPortFromName('InName')
outPort = getDataNodeGeo.GetPortFromName('outName')
xsi.ConnectICENodes(inPort,outPort)
# Create Multiply Node
multiplyNode = xsi.AddICENode('MultiplyNode', tree)
# Connect Geo and Manipulator to Multiply Node
inPort = multiplyNode.GetPortFromName('value1')
outPort = getDataNodeKineGlobal.GetPortFromName('value')
xsi.ConnectICENodes(inPort,outPort)
# Connect Manipulator Null to Multiply Node
inPort = multiplyNode.GetPortFromName('value2')
outPort = getDataManipulatorKineGlobalNode.GetPortFromName('value')
xsi.ConnectICENodes(inPort,outPort)
# Create Set Data Node
setDataNode = xsi.AddICECompoundNode("Set Data", tree)
xsi.SetValue("%s.Reference" % setDataNode, "kine.global")
# Connect Geo Name to Set Data
inPort = setDataNode.GetPortFromName('In_Name')
outPort = getDataNodeGeo.GetPortFromName('outName')
xsi.ConnectICENodes(inPort,outPort)
# Connect Multiply to Set Data
inPort = setDataNode.GetPortFromName('Value')
outPort = multiplyNode.GetPortFromName('result')
xsi.ConnectICENodes(inPort,outPort)
# Finally Connect Set Data to Execute
inPort = "%s.port1" % tree
outPort = setDataNode.GetPortFromName('Execute')
xsi.ConnectICENodes(inPort,outPort)
@disableLog()
def main():
# Check Selection
if len(list(xsi.Selection))==0:
log("No geo selected", c.siWarning)
return
# Ask User to move to first frame
_moveToFirstFrame()
# Creates Trees for Selected Geo
for geo in xsi.Selection:
_createTree(geo)
return
main()
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ALOK
GANDHI
/ chef directeur technique - lead technical director
[email protected] <mailto:[email protected]>
T:
*450 430-0010 x225
F:
*450 430-0009
www.modusfx.com <http://www.modusfx.com>
---------------------------------------------------------------------------------------------
MODUS
FX
120 Rue Turgeon,
Sainte-Therese (Quebec) CANADA J7E 3J1
Follow us on
Facebook <http://www.facebook.com/ModusFX>
&
Twitter <https://twitter.com/Modusfx>
**
On 04/03/2013 1:29 PM, Peter Agg wrote:
I would say that this is where a more functional programming approach
may be neater. That way you can hide all the nastyness away in small
functions elsewhere and then just stick a suspiciously tidy looking
map() in the main Execute.
On 4 March 2013 18:02, Eric Thivierge <[email protected]
<mailto:[email protected]>> wrote:
On Mon, Mar 4, 2013 at 12:58 PM, Peter Agg
<[email protected] <mailto:[email protected]>> wrote:
Prepare yourself for some ugly, ugly code when it comes to
ICE! Nice long command names as well. :)
Indeed. A mix of OM and commands is necessary. You can query ports
via OM but you'll need to use commands to connect stuff. Have fun
you'll find it to be frustrating.
--------------------------------------------
Eric Thivierge
http://www.ethivierge.com
No virus found in this message.
Checked by AVG - www.avg.com <http://www.avg.com>
Version: 2012.0.2238 / Virus Database: 2641/5646 - Release Date: 03/03/13