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 SDK wierdness with importing Application object explicitly within mod

Python SDK wierdness with importing Application object explicitly within mod

2005-04-14       - By Luke Emrose

 Back
Reply:     1     2  

Cheers for the info,

I am getting this change implemented here now for some tests to see if
it fixes the issue.

Thanks in advance.

Luke

Bernard Lebel wrote:

> Hi Luke,
>
> Every python users have wondered the same thing at one point or
> another.... here what Soft has to say about that (from Jerry Gamache):
>
>
>
>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.
>  
>
>
>
>
>
> Luke Emrose wrote:
>
>> I am about to go nutz on this....
>>
>> Before I whinge about the implementation of Python in XSI,
>> maybe someone can tell me I am doing something stupid so I can fix
>> this issue once and for all.
>>
>> OK, I am modularising my code into python modules and recently
>> discovered that you can do the following from
>> a module to import the normal Application and XSIFactory etc. objects
>> for use within that module :
>>
>> /import win32com
>> ap = win32com.client.Dispatch( 'XSI.Application' ).Application
>> XSIFactory = win32com.client.Dispatch( 'XSI.Factory' )
>> XSIMath = win32com.client.Dispatch( 'XSI.Math' )
>> from win32com.client import constants as c
>> /
>> which is my typical set of imports at the start of all of my modules.
>>
>> (my previous solution, which worked flawlessly but is the most stupid
>> way EVER to have to do it, was passing in the Application
>> object from the base script (as Application is defined and bound
>> within it by default) and then pass it on to every other module
>> explicitly, which is only possible in Python via it's lack of
>> type-checking until run-time.  However this is entirely different to
>> the way
>> that every other supported scripting language within XSI does things,
>> as with them it is a lot easier to get hold of the Application object. )
>>
>> The stupid thing is now, despite this is the ONLY thing I have
>> changed in my code from before where Application
>> was passed in explicitly, EVERY statement where I do an
>> object.Properties( "#some_property" ) call fails with
>> the following error:
>>
>> for instance trying to get to the viewvis attribute:
>>
>> /File
>> "/usr/Softimage/XSI_4.2/Application/bin/win32com/client/__init__.py",
>> line 454, in __getattr__
>> #    raise AttributeError, "'%s' object has no attribute '%s'" %
>> (repr(self), attr)
>> #AttributeError: '<win32com.gen_py.Softimage|XSI Object Model Library
>> v1.5.Property instance at 0x1669476908>' object has no attribute
>> 'viewvis'
>> # - [line 453]
>> #ERROR : OLE error 0x80020101/
>>
>> Wrapping up the Properties call like this ap.GetValue(
>> object.Properties( "#some_property" ) ) helps in some situation, but
>> even then there are a lot of
>> cases where it still fails.  Since the ONLY thing I changed in my
>> code is the way I am importing Application, things like this should
>> not stop working.
>>
>> If I've done something obviously wrong could people please let me
>> know, or is there something else I am missing.
>>
>> Sorry bout the longwindedness but I'm trying to be as clear as
>> possible here.
>>
>> cheers,
>>
>> Luke
>>
>>--
>>luke emrose
>>vfx artist - luke@(protected) <mailto:luke@(protected)>
>>-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
>>rising sun pictures - www.rsp.com.au <http://www.rsp.com.au>
>>redefining visual effects delivery
>>-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
>>mb  - 0408 893 505
>>adl - ph +61 8 7421 6400 - fx +61 8 7421 6401
>>syd - ph +61 2 9338 6400 - fx +61 2 9338 6401
>>-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
>>rising sun research - http://research.rsp.com.au
>>cineSpace color management solutions for film
>>  
>>
>
> --- Unsubscribe? Mail Majordomo@(protected) with the following text
> in body: unsubscribe xsi



--
luke emrose
vfx artist - luke@(protected)
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun pictures - www.rsp.com.au
redefining visual effects delivery
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
mb  - 0408 893 505
adl - ph +61 8 7421 6400 - fx +61 8 7421 6401
syd - ph +61 2 9338 6400 - fx +61 2 9338 6401
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun research - http://research.rsp.com.au
cineSpace color management solutions for film


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <meta content="text/html;charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1" http-equiv="Content-Type">
 <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Cheers for the info,<br>
<br>
I am getting this change implemented here now for some tests to see if
it fixes the issue.<br>
<br>
Thanks in advance.<br>
<br>
Luke<br>
<br>
Bernard Lebel wrote:
<blockquote cite="mid425F3C52.3000403@(protected)" type="cite">
 <meta http-equiv="Context-Type"
content="text/html; charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1">
 <title></title>
Hi Luke,<br>
 <br>
Every python users have wondered the same thing at one point or
another.... here what Soft has to say about that (from Jerry Gamache):<br>
 <br>
 <br>
 <br>
 <pre>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.
 </pre>
 <br>
 <br>
 <br>
 <br>
Luke Emrose wrote:
 <blockquote cite="mid425F3538.6050400@(protected)" type="cite">
   <title></title>
I am about to go nutz on this....<br>
   <br>
Before I whinge about the implementation of Python in XSI,<br>
maybe someone can tell me I am doing something stupid so I can fix this
issue once and for all.<br>
   <br>
OK, I am modularising my code into python modules and recently
discovered that you can do the following from<br>
a module to import the normal Application and XSIFactory etc. objects
for use within that module :<br>
   <br>
   <i>import win32com<br>
ap = win32com.client.Dispatch( 'XSI.Application' ).Application<br>
XSIFactory = win32com.client.Dispatch( 'XSI.Factory' )<br>
XSIMath = win32com.client.Dispatch( 'XSI.Math' )<br>
from win32com.client import constants as c<br>
   </i><br>
which is my typical set of imports at the start of all of my modules.<br>
   <br>
(my previous solution, which worked flawlessly but is the most stupid
way EVER to have to do it, was passing in the Application<br>
object from the base script (as Application is defined and bound within
it by default) and then pass it on to every other module<br>
explicitly, which is only possible in Python via it's lack of
type-checking until run-time.&nbsp; However this is entirely different to
the way<br>
that every other supported scripting language within XSI does things,
as with them it is a lot easier to get hold of the Application object. )<br>
   <br>
The stupid thing is now, despite this is the ONLY thing I have changed
in my code from before where Application<br>
was passed in explicitly, EVERY statement where I do an
object.Properties( "#some_property" ) call fails with<br>
the following error:<br>
   <br>
for instance trying to get to the viewvis attribute:<br>
   <br>
   <i>File
"/usr/Softimage/XSI_4.2/Application/bin/win32com/client/__init__.py",
line 454, in __getattr__<br>
#&nbsp;&nbsp;&nbsp; raise AttributeError, "'%s' object has no attribute '%s'" %
(repr(self), attr)<br>
#AttributeError: '&lt;win32com.gen_py.Softimage|XSI Object Model
Library v1.5.Property instance at 0x1669476908&gt;' object has no
attribute 'viewvis'<br>
# - [line 453]<br>
#ERROR : OLE error 0x80020101</i><br>
   <br>
Wrapping up the Properties call like this ap.GetValue(
object.Properties( "#some_property" ) ) helps in some situation, but
even then there are a lot of<br>
cases where it still fails.&nbsp; Since the ONLY thing I changed in my code
is the way I am importing Application, things like this should not stop
working.<br>
   <br>
If I've done something obviously wrong could people please let me know,
or is there something else I am missing.<br>
   <br>
Sorry bout the longwindedness but I'm trying to be as clear as possible
here.<br>
   <br>
cheers,<br>
   <br>
Luke<br>
   <pre>--
luke emrose
vfx artist - <a href="mailto:luke@(protected)">luke@(protected)</a>
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun pictures - <a href="http://www.rsp.com.au">www.rsp.com.au</a>
redefining visual effects delivery
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
mb  - 0408 893 505
adl - ph +61 8 7421 6400 - fx +61 8 7421 6401
syd - ph +61 2 9338 6400 - fx +61 2 9338 6401
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun research - <a href="http://research.rsp.com.au">http://research.rsp
.com.au</a>
cineSpace color management solutions for film
 </pre>
 </blockquote>
 <br>
---
Unsubscribe? Mail <a class="moz-txt-link-abbreviated" href="mailto:Majordomo
@(protected)">Majordomo@(protected)</a> with the following text in
body:
unsubscribe xsi
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
luke emrose
vfx artist - <a class="moz-txt-link-abbreviated" href="mailto:luke@(protected)"
>luke@(protected)</a>
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun pictures - <a class="moz-txt-link-abbreviated" href="http://www.rsp
.com.au">www.rsp.com.au</a>
redefining visual effects delivery
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
mb  - 0408 893 505
adl - ph +61 8 7421 6400 - fx +61 8 7421 6401
syd - ph +61 2 9338 6400 - fx +61 2 9338 6401
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
rising sun research - <a class="moz-txt-link-freetext" href="http://research
.rsp.com.au">http://research.rsp.com.au</a>
cineSpace color management solutions for film
</pre>
</body>
</html>