  | | | avoiding using get value with python | avoiding using get value with python 2005-03-25 - By Bernard Lebel
Back Thanks a bunch Jerry for this precious info. Hope it gets put in the skd docs :-)
Bernard
Jerry Gamache wrote: > 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.
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |