Re: [scripting] The Models property in Python...

Date : Fri, 22 Sep 2006 18:50:44 +1000
To : XSI(at)Softimage.COM
From : "Aloys Baillet" <aloys.baillet(at)gmail.com>
Subject : Re: [scripting] The Models property in Python...
Hello,

Just resurrecting this thread...
I just found a way of calling properties with arguments in Python that works well. Shame I didn't see that before!

def getCOMPropWithArgs(obj, propName, *args):
    iid = obj._oleobj_.GetIDsOfNames(propName)
    return obj._oleobj_.Invoke(iid, 0, 2, 1, *args)
   
#Usage:
from win32com.client import constants as c

branchSelected = getCOMPropWithArgs(Application.ActiveSceneRoot, 'Selected', c.siBranch)
print 'Branch?: %s'%branchSelected

models = getCOMPropWithArgs(Application.ActiveSceneRoot, 'Models', False)
if models.Count > 0:
    print [m.Name for m in models]


Hope this might help someone...

Aloys


On 8/11/06, Aloys Baillet <aloys.baillet@gmail.com> wrote:
Thanks Marc-AndrÃ, but it doens't seem to work! I'm using XSI 5.11, and here's what I get if I try to call the GetModel method:

#ERROR : Traceback (most recent call last):
#  File "<Script Block >", line 81, in SBHelpersEvents_OnBeginFileImport_OnEvent
#    subModels = parent.GetModels(False)
#  File "c:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 489, in __getattr__
#    raise AttributeError, "%s.%s" % (self._username_, attr)
#AttributeError: <unknown>.GetModels

Any idea why I don't have this method exposed?
I tried to activate the dynamic dispatch with Patrick Boucher's technique( http://www.xsi-blog.com/?p=24 ), but no change!

Cheers,

Aloys


On 8/10/06, Marc-Andrà Belzile <mbelzile@softimage.com > wrote:
Try with GetModels. It is actually generated by Python from the Models property, but must be used as a method to correctly pass the arguments.
 
-mab
-----Original Message-----
From: owner-xsi@Softimage.COM [mailto:owner-xsi@Softimage.COM]On Behalf Of Aloys Baillet
Sent: August 10, 2006 2:03 AM
To: xsi@Softimage.COM
Subject: Re: [scripting] The Models property in Python...

Because Python is great:
    models = filter(lambda x: x.Parent.Name == myX3D.Name, myX3D.Models)
Because COM is less great:
   anyone with a faster idea is still welcome!

Aloys

On 8/10/06, Aloys Baillet <aloys.baillet@gmail.com> wrote:
Hello there,

A really basic question... maybe?

I need to get the list of models under any given X3DObject, but NOT the recursive list: just the direct children.

The X3DObject.Models property accepts a Recursive argument (thanks Bill for this great feature: properties with arguments...).

In JScript, it's quite easy:
var models = myX3D.Models(false)
will return the good list.

Unfortunately in Python,
models = myX3D.Models(False)
returns the first item of the recursive list (False being evaluated as 0, and the recursive list being always returned)!

Any great, simple and clean idea anyone?

Cheers,

Aloys


--
Aloys Baillet - XSI Technical Director
Character Dpt - Animal Logic
--



--
Aloys Baillet - XSI Technical Director
Character Dpt - Animal Logic
--



--
Aloys Baillet - XSI Technical Director
Character Dpt - Animal Logic
--



--
Aloys Baillet - XSI Technical Director
Character Dpt - Animal Logic
--

Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.