Mailing List
Home
Forum Home
Softimage
Carrara
trueSpace
Dir3d-l
Maya - a powerful 3D animation and visual effects software
Macromedia Flash Development
Subjects
Cameras
scaleDown command
black out solved
Aircraft Tutorial
Mathematical XYZ ?
Its done This vs That
Its done first week
recommendations for screen video captures?
3DExplorer "Oddity "
New Director
ProTeam renewals
Fuel 's new websites (X post)
Blue peter create a make toy
targeting groups question
XPost: Shockwave 3D game ( sort of )
RES: RES: RES: Fish Modeling
Emitting particles from object intersection
Fuel 's new websites (X post)
Texturing
Big Break Contest Videos
New Plugins
Models and Texture on my updated site
Error Installing Patch tS6 6
Plasma?
Looking for Inspiration
Weird EMail Q
It 's done first week ?
Cherry not cranberry
New game
Camera Animation Problem
Particle plugins?
 
Python introspection...

Python introspection...

2005-06-13       - By Hans,Veenendaal,AMplus R&D,SOJ

 Back
Reply:     1     2     3     4     5     6     7     8     9     10  

This works for me.

App = Application
for obj in App.Selection:
 Test = obj.LocalProperties
 LogMessage(str(obj) + " has " + str(Test.Count) + " local properties")

If this fails than you have things selected that are not SceneItem
derived objects...

LocalProperties only exist on SceneItem derived objects. Selecting a
polymsh or kine will crash with
the (<unknown>.localproperties) error.

You could check if the obj is derived from SceneItem, but I have no idea
on how to do that in python.
It should be possible to QueryInterface with the SceneItem IID
{31903CD0-EDFB-11 (See http://DFB-11.ora-code.com)D3-ACCC-0090275802 (See http://CCC-0090275802.ora-code.com)BF} through python win32com
support...
Maybe somebody else can fill in the blanks here.

In ATLCOM it is farely simple:
CComQIPtr<ISceneItem> pItem = pObj;   // Get the ISceneItem interface
from the Object
if(pItem != NULL)
{
 // We are dealing with a ISceneItem derived object.
}

Hans

>-- --Original Message-- --
>From: owner-xsi@(protected) [mailto:owner-xsi@(protected)]
>On Behalf Of Bernard Lebel
>Sent: Saturday, June 11, 2005 5:29 AM
>To: XSI@(protected)
>Subject: Re: Python introspection...
>
>Hello,
>
>Is there an easier way to check if an object has, for example,
>the "LocalProperties" attribute, other than by going through
>such a chunk of code?
>
>Right now I have this:
>
>xsi = Application
>
>oObject = xsi.selection(0)
>
># Iterate object attributes
>for i in xrange( 0, oObject._oleobj_.GetTypeInfoCount() ):
>
>   typeInfo = xsi.selection(0)._oleobj_.GetTypeInfo( i )
>   typeAttr = typeInfo.GetTypeAttr()
>  
>   # Iterate "functions" of object
>   for iFunction in xrange( 0, typeAttr.cFuncs ):
>    
>     functionDescription = typeInfo.GetFuncDesc( iFunction )
>    
>     # Get name of function (even if function is
>actually a property)
>     sName = typeInfo.GetNames(
>functionDescription.memid )[0]
>    
>     if sName == 'LocalProperties': xsi.logmessage( 'yeah!' )
>
>
>I have tried simpler approches, like
>
>if not oObject.localproperties: xsi.logmessage( 'no' )
>
>But I get an attribute error (<unknown>.localproperties).
>
>
>Thanks
>Bernard
>
>
>
>
>On 4/6/05, Jerry Gamache <jerryg@(protected)> wrote:
>> Once you know the function name, you sometimes want to get
>some very terse documentation:
>>
>> def FormatDocumentation(typeInfo, funDesc):
>>         nameAndParms = typeInfo.GetNames(funDesc.memid)
>>         docum = typeInfo.GetDocumentation(funDesc.memid)
>>         import pythoncom
>>         # This one differentiates between "functions" and "accessors"
>>         if funDesc.invkind == pythoncom.INVOKE_FUNC:
>>                 docStr = nameAndParms[0] + "(" +
>",".join(nameAndParms[1:]) + ")\n"
>>         else:
>>                 docStr = nameAndParms[0] + "\n"
>>         if docum[1]:
>>                 docStr += "\t" + docum[1]
>>         return docStr
>>
>> def GetDocumentation( dynDisp, funcName = None ):
>>         allTypeInfoDoc = []
>>         for iTI in xrange(0,dynDisp._oleobj_.GetTypeInfoCount()):
>>                 typeInfo = dynDisp._oleobj_.GetTypeInfo(iTI)
>>                 typeAttr = typeInfo.GetTypeAttr()
>>                 if funcName:
>>                         for iFun in xrange(0,typeAttr.cFuncs):
>>                                 funDesc = typeInfo.GetFuncDesc(iFun)
>>                                 name =
>typeInfo.GetNames(funDesc.memid)[0]
>>                                 if name.upper() == funcName.upper():
>>                                         return
>FormatDocumentation(typeInfo, funDesc)
>>                 else:
>>                         dict = {}
>>                         className =
>dynDisp._oleobj_.GetTypeInfo(0).GetDocumentation(-1)
>>                         classDoc = "class %s
>\n\t%s\n\n"%(className[0],className[1])
>>                         allFuncDoc = []
>>                         for iFun in xrange(0,typeAttr.cFuncs):
>>                                 funDesc = typeInfo.GetFuncDesc(iFun)
>>                                 name =
>typeInfo.GetNames(funDesc.memid)[0]
>>                                 if not dict.has_key(name):
>>                                         dict[name] = 1
>>                                        
>allFuncDoc.append(FormatDocumentation(typeInfo, funDesc))
>>                         allFuncDoc.sort()
>>                         allTypeInfoDoc.append(classDoc +
>"\n".join(allFuncDoc))
>>         if funcName:
>>                 return "Documentation not found for %s"%(funcName,)
>>         else:
>>                 return "\n".join(allTypeInfoDoc)
>>
>> # 2 ways to call this one: without a function name it retrieves doc
>> for all functions
>> Application.LogMessage(GetDocumentation(Application))
>> # And with a name, it tries to find the doc for that function:
>> Application.LogMessage(GetDocumentation(Application, "StatusBar"))
>> Application.LogMessage(GetDocumentation(Application, "NotThere"))
>
>---
>Unsubscribe? Mail Majordomo@(protected) with the following
>text in body:
>unsubscribe xsi
>

---
Unsubscribe? Mail Majordomo@(protected) with the following text in body:
unsubscribe xsi