Although minor, you could move exp.OutputPorts.Count a little earlier in your
code as it's testing the same thing for each input port on the operator. You
should only have to test that once per expression, like this:
def getExpressionsDrivenByParameter( param ):
allExpressions = xsi.FindObjects(None,
"{12723EB2-7DDB-11D0-A57F-00A0C91412DE}")
result = []
for exp in allExpressions:
if exp.OutputPorts.Count:
for port in exp.InputPorts:
if port.Target2.IsEqualTo(param):
result.append(exp)
break
return result
Other than that, you're dealing with an O(n^2) runtime. The only way to make
it significantly faster is to unroll the loops, but may not be possible for
this task. You could try reading the "target" and "definition" parameters of
the expression, but those may be ambiguous for some cases and also result in
string comparisons which may or may not be faster.
Matt
From: [email protected]
[mailto:[email protected]] On Behalf Of Jeremie Passerin
Sent: Friday, July 27, 2012 2:44 PM
To: softimage
Subject: get all the expressions driven by a parameter
Hi guys,
I was wondering what is your technique to get all the expressions driven by a
parameter.
I'm trying to find the fastest way to do it.
here is my code :
def getExpressionsDrivenByParameter( param ):
allExpressions = xsi.FindObjects(None,
"{12723EB2-7DDB-11D0-A57F-00A0C91412DE}")
result = []
for exp in allExpressions:
for port in exp.InputPorts:
if port.Target2.IsEqualTo(param) and exp.OutputPorts.Count:
result.append(exp)
break
return result
With around 5000 expressions in my scene it takes about 2sec to get the result.
Anyone got a faster solution ?
cheers,
Jeremie