Getting all visibility.viewvis parameters


From a discussion on the mailing list today, a few of the different ways to get every instance of a specific parameter, and some [crude] timing of the different methods.

I was also glad to see confirmation that using wildcards like “*.visibility” pick up everything (because I’ve never got any variation of “*#3dobject” to pick up all objects).

si = Application
import time
from win32com.client import Dispatch as disp
from win32com.client import constants as c


t = time.clock()
oObj = disp("XSI.Collection")
oObj.Items = "*.visibility"
for o in oObj:
	v = o.viewvis.Value
print 'XSICollection.Items  : count=%s, time=%s' % ( oObj.Count, time.clock() - t )


t = time.clock()
oObj.Items = "*.visibility.viewvis"
for o in oObj:
	v = o.Value
print 'XSICollection.Items  : count=%s, time=%s' % ( oObj.Count, time.clock() - t )



t = time.clock()
items = si.ActiveSceneRoot.FindChildren2()
for obj in items:
    vis = obj.GetPropertyFromName2("Visibility")
    v = vis.viewvis.value
print 'GetPropertyFromName2 : count=%s, time=%s' % ( items.Count, time.clock() - t )


t = time.clock()
items = si.ActiveSceneRoot.FindChildren2()
for obj in items:
    v = obj.Properties('visibility').Parameters('viewvis').Value   
print 'Properties.Parameters: count=%s, time=%s' % ( items.Count, time.clock() - t )


t = time.clock()
items = si.ActiveSceneRoot.FindChildren2()
for item in items:
    si.Tag(item.fullname + '.visibility.viewvis', c.siTag1)
print 'Tag()                : count=%s, time=%s' % ( items.Count, time.clock() - t )

t = time.clock()
items = si.ActiveSceneRoot.FindChildren2()
for item in items:
	p = item.Properties( "Visibility" ).Parameters( "viewvis" )
	p.Tags = c.siTag1
print 'Parameter.Tag        : count=%s, time=%s' % ( items.Count, time.clock() - t )


t = time.clock()
val = si.ActiveSceneRoot.TaggedParameters(c.siTag1, False)
for v in val:
    v = v.value
print 'TaggedParameters     : count=%s, time=%s' % ( items.Count, time.clock() - t )

Notice how turning off command logging speeds up those two commands:

# XSICollection.Items  : count=4367, time=1.18428964264
# XSICollection.Items  : count=4367, time=1.00415073153
# GetPropertyFromName2 : count=4367, time=2.07334397855
# Properties.Parameters: count=4367, time=4.38064481075
# Tag()                : count=4367, time=20.6681847681
# Parameter.Tag        : count=4367, time=5.11316244631
# TaggedParameters     : count=4367, time=0.705648810261
Application.SetValue("preferences.scripting.cmdlog", False, "")
# XSICollection.Items  : count=4367, time=1.16849869148
# XSICollection.Items  : count=4367, time=0.988541493731
# GetPropertyFromName2 : count=4367, time=2.03344763365
# Properties.Parameters: count=4367, time=4.33773781962
# Tag()                : count=4367, time=7.47015675041
# Parameter.Tag        : count=4367, time=4.99573667863
# TaggedParameters     : count=4367, time=0.687065751859

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s