I suspect it to be the runtime dispatching and attribute access (dictionary
lookups) cost...
Tho the Tag command allow us to pass a collection instead of giving
sequentially items, this resulting in a great improvement.
-- jon




2013/2/28 Matt Lind <ml...@carbinestudios.com>

> Interesting how much choice of language affects performance. ****
>
> ** **
>
> In your tests the Object model has the same runtime as calling commands.
> On my computer using Jscript, the object model is at least 4x faster than
> calling Tag() command.  ****
>
> ** **
>
> ** **
>
> Matt****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> *From:* softimage-boun...@listproc.autodesk.com [mailto:
> softimage-boun...@listproc.autodesk.com] *On Behalf Of *jo benayoun
> *Sent:* Thursday, February 28, 2013 2:49 PM
> *To:* softimage@listproc.autodesk.com
>
> *Subject:* Re: fastest way through script to get all parameters in a
> scene of certain value?****
>
> ** **
>
> Hey Enoch,****
>
> unless I missed something, the way you're doing is already the fastest on
> my machine...****
>
> ** **
>
> ** **
>
> for reference:****
>
> ** **
>
> # INFO : tag operation1 (tag): 2.13486326588****
>
> # INFO : tag operation2 (tag+): 18.2174550721****
>
> # INFO : tag operation3 (OM): 18.2086833524****
>
> # INFO : get operation1 (tagparams): 0.452397979784 4204****
>
> # INFO : get operation2 (xsicoll): 7.46562998296 4204****
>
> ** **
>
> ** **
>
> import time****
>
> from win32com.client import constants****
>
> class Softimage:****
>
>     __getattr__ = lambda x, a: getattr(Application, a, False) or
> getattr(constants, a)****
>
> softimage = Softimage()****
>
> softimage.factory = XSIFactory****
>
> softimage.message = lambda x, *args:
> softimage.LogMessage(str(x).format(*args))****
>
> softimage.SetUserPref("SCR_CMDLOG_ENABLED", False)****
>
> items = softimage.ActiveSceneRoot.FindChildren2()****
>
> ** **
>
> ** **
>
> t = time.clock()****
>
> parameters = ["{0}.visibility.viewvis".format(x) for x in items]****
>
> softimage.Tag(parameters, softimage.siTag1)****
>
> softimage.message("tag operation1 (tag): {0}", time.clock() - t)****
>
> ** **
>
> t = time.clock()****
>
> for item in items:****
>
>     softimage.Tag(item.FullName + '.visibility.viewvis', softimage.siTag1)
> ****
>
> softimage.message("tag operation2 (tag+): {0}", time.clock() - t)****
>
> ** **
>
> t = time.clock()****
>
> tag1 = softimage.siTag1****
>
> parameters = (x.Properties("visibility").Parameters("viewvis") for x in
> items)****
>
> for parameter in parameters:****
>
>     parameter.Tags |= tag1****
>
> softimage.message("tag operation3 (OM): {0}", time.clock() - t)****
>
> ** **
>
> t = time.clock()****
>
> params = softimage.ActiveSceneRoot.TaggedParameters(softimage.siTag1)****
>
> softimage.message("get operation1 (tagparams): {0} {1}", time.clock() - t,
> params.Count)****
>
> ** **
>
> t = time.clock()****
>
> parameters = softimage.factory.CreateObject("XSI.Collection")****
>
> parameters.SetAsText("*.visibility.viewvis")****
>
> parameters = [x for x in parameters if x.Tags & softimage.siTag1]****
>
> softimage.message("get operation2 (xsicoll): {0} {1}", time.clock() - t,
> len(parameters))****
>
> ** **
>
> parameters = (x.Properties("visibility").Parameters("viewvis") for x in
> items)****
>
> for param in parameters:****
>
>     param.Tags &= ~softimage.siTag1****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> 2013/2/28 Matt Lind <ml...@carbinestudios.com>****
>
> Retrieving the value is the same.  If you use the object model you’ll have
> direct access to the parameter whether it’s the tag or the value.  Just
> switch “oParameter.Tags” with “oParameter.value” in my example and you have
> your answer.****
>
>  ****
>
> If you’re looking to retrieve a specific value, or parameters with a
> common value, then you have no choice but to loop through all of them and
> do comparisons to find what you’re looking for.  In your case using the
> other notation with wildcards is only useful if you’re setting a set of
> parameters to a common value.****
>
>  ****
>
>  ****
>
> Matt****
>
>  ****
>
>  ****
>
> *From:* softimage-boun...@listproc.autodesk.com [mailto:
> softimage-boun...@listproc.autodesk.com] *On Behalf Of *Enoch Ihde
> *Sent:* Thursday, February 28, 2013 10:00 AM****
>
>
> *To:* softimage
> *Subject:* Re: fastest way through script to get all parameters in a
> scene of certain value?****
>
>  ****
>
> sorry, i wasn't really clear.  i'm aware the tagging bit was slow, i
> couldn't be bothered to tag it object modelwise.
>
> i'm referring only to the value retrieval of the parameter.  not the setup
> time.****
>
> again:
> # INFO : 0.788785183814 seconds <--- accessing 3618 parameters's values by
> tag
>
> # INFO : 2.12563553863 seconds  <--- accesssing 3618 parameters's values
> by GetPropertyFromName2(propertyname).Parameters(paramname)
>
> # INFO : 7.84713397563 <---- accessing 3618 parameter's values by
> Property(propertyname).Parameters(paramname)****
>
> tagging is by far the fastest, but in imo, is unacceptably slow.
> compare that to a method such as IsSelected(), getting a report on a large
> number of objects is negligible. ****
>
>  ****
>
>  ****
>
> On Wed, Feb 27, 2013 at 10:29 PM, Matt Lind <ml...@carbinestudios.com>
> wrote:****
>
> The slowness is coming from using the Tag() command.  Try using the object
> model to cut out the middle man:****
>
>  ****
>
> // Jscript****
>
> main();****
>
>  ****
>
> function main()****
>
> {****
>
>                 var oItems = ActiveSceneRoot.FindChildren2();****
>
>                 ****
>
>                 LogMessage( oItems.Count );****
>
>                 ****
>
>                 for ( var i = oItems.Count - 1; i >= 0; i--) {****
>
>                 ****
>
>                                 var oItem       = oItems(i);****
>
>                                 var oParameter  = oItem.Properties(
> "Visibility" ).Parameters( "viewvis" );****
>
>                                 oParameter.Tags = siTagNone;****
>
>                 }****
>
>                 ****
>
>                 return;****
>
> }****
>
>  ****
>
>  ****
>
> If the parameters you are attempting to modify have a large degree of
> consistency in name and location, you can use some of Softimage’s wildcards
> to find them faster:****
>
>  ****
>
> var oParameters = XSIFactory.CreateActiveXObject( “XSI.Collection” );****
>
> oParameters.Unique = true;****
>
>  ****
>
>                 // Get viewvis and rendvis parameters of the visibility
> property on each X3DObject****
>
> oParameters.items = “*.visibility.{viewvis,rendvis}”;****
>
>  ****
>
> LogMessage( oParameters.Count );****
>
>  ****
>
> If there is a large degree of consistency in the parameter fullname, you
> can apply values to the parameters en masse very efficiently:****
>
>  ****
>
>                 SetValue( “*.visibility.{viewvis,rendvis}", false );****
>
>  ****
>
>  ****
>
> Matt****
>
>  ****
>
>  ****
>
>  ****
>
>  ****
>
> *From:* softimage-boun...@listproc.autodesk.com [mailto:
> softimage-boun...@listproc.autodesk.com] *On Behalf Of *Enoch Ihde
> *Sent:* Wednesday, February 27, 2013 9:55 PM
> *To:* softimage
> *Subject:* Re: fastest way through script to get all parameters in a
> scene of certain value?****
>
>  ****
>
> better stated: certain parameter name, not value, apologies, running
> behind on sleep, words are challenging. ****
>
> On Feb 27, 2013 7:54 PM, "Enoch Ihde" <emi...@gmail.com> wrote:****
>
> these are the three methods i've tried.****
>
> using tags is the fastest, but a little prohibitive, as you have to have
> anticipated needing to get a param quickly, so it must be tagged in
> advance.  also, even with getting by tags, performance imo is pretty poor.
>
> results on my machine from the code below:
> # INFO : object count is 3618
> # INFO : 0.788785183814
> # INFO : tagged param count is 3618
> # INFO : 2.12563553863
> # INFO : 7.84713397563****
>
> is there a better way?****
>
> <snip>****
>
> import time
> import win32com.client
> xsi    = win32com.client.Dispatch( "XSI.Application" ).Application
> xsiPrint = xsi.LogMessage
> from win32com.client     import constants as c
> items = xsi.ActiveSceneRoot.FindChildren2()****
>
> ##### this bit is really slow****
>
> for item in items:
>     xsi.Tag(item.fullname + '.visibility.viewvis', c.siTag1)
> xsiPrint('object count is ' + str(items.count))****
>
> #### and only needs to be run once****
>
> t = time.clock()
> val = xsi.ActiveSceneRoot.TaggedParameters(c.siTag1, False)
> for v in val:
>     someStuff = v.value
> xsiPrint(time.clock() - t)
>
> xsiPrint('tagged param count is ' + str(val.count))
>
> t = time.clock()
> for obj in items:
>     vis = obj.GetPropertyFromName2("Visibility")
>     v = vis.viewvis.value
> xsiPrint(time.clock() - t)
>
>
> t = time.clock()
> for obj in items:
>     vis = obj.Properties('visibility').Parameters('viewvis').value    ****
>
> xsiPrint(time.clock() - t)****
>
> </snip>****
>
> tia,****
>
> enoch****
>
>  ****
>
>  ****
>
> ** **
>

Reply via email to