  | | | avoiding using get value with python | avoiding using get value with python 2005-03-17 - By Jerry Gamache
Back XSI sometimes return objects with an incorrectly set (as per PythonWin standards) multi-dispatch interface.
The way to work around that is to re-wrap the object in a dynamic dispatch. This allows you to skip the Application.GetValue:
def dispFix( badDispatch ): import win32com.client.dynamic # Re-Wraps a bad dispatch into a working one: return win32com.client.dynamic.Dispatch(badDispatch)
# Let's see if this works: Application.CreatePrim("Sphere", "MeshSurface", "", "") Application.ApplyHairOp("sphere", "") oHair = Application.GetValue("hair").ActivePrimitive.ConstructionHistory.Find( "HairGenOp") try: Application.LogMessage(oHair.Parameters['EmitterMeshSubdlevel'].Value) except: Application.LogMessage("Incorrect dispatch pointer") oHair = dispFix(oHair) Application.LogMessage(oHair.Parameters['EmitterMeshSubdlevel'].Value)
# or, as a single long line:
dispFix(Application.GetValue("hair") .ActivePrimitive.ConstructionHistory .Find("HairGenOp") ).Parameters['EmitterMeshSubdlevel'].Value = 1
If that really really annoys you and you don't want to dispFix at all, there is a way to make sure everything works, but you need to modify a Python file to always return dynamic dispatches:
Change %PYTHONPATH%\Lib\site-packages\win32com\client\__init__.py
Look for the function called __WrapDispatch
And comment all lines except the last one that begins with "return dynamic .Dispatch( ... "
Of course it is always a good idea to backup files you are about to modify.
-- --Original Message-- -- From: owner-xsi@(protected) [mailto:owner-xsi@(protected)]On Behalf Of kim@(protected) Posted At: Thursday, March 17, 2005 12:07 PM Posted To: xsi Conversation: avoiding using get value with python Subject: Re: avoiding using get value with python
Check out Brad Gabe's excelent article 'Looping Lizards' at www.cg-soup.com for fast and efficient ways to get objects using the OM.
softimage@(protected) writes:
> You may use Application.dictionary.getobject() > > You may also iterate the ConstructionHistory and check each operators > individually. The docs have a good example about this. Once you have found the > operator you can simly access its parameters: > iValue = oOperator.parameters( 'EmitterMeshSubdlevel' ).value > > > Cheers > Bernard > > > Quoting benp <benp@(protected)>: > >> hello xsiList! >> I haven't tried to get operator objects before, so this may be a larger >> problem than just using GetValue ... >> in python and with a hair object selected: >> oTo = Application.Selection(0) >> > Application.GetValue(oTo.ActivePrimitive.ConstructionHistory.Find("hairGenOp" )).Parameters("EmitterMeshSubdlevel").Value >> = 0 >> >> how can i avoid using GetValue to get the hairGenOp object properly? >> I often find i can't get objects without using GetValue. >> >> thanks list. >> >> >> --- >> Unsubscribe? Mail Majordomo@(protected) with the following text in body: >> unsubscribe xsi >> > > > > --- > Unsubscribe? Mail Majordomo@(protected) with the following text in body: > unsubscribe xsi >
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |