  | | | Python SDK wierdness with importing Application object explicitly within modules | Python SDK wierdness with importing Application object explicitly within modules 2005-04-14 - By Luke Emrose
Back 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) -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- 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"> 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. 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> # raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)<br> #AttributeError: '<win32com.gen_py.Softimage|XSI Object Model Library v1.5.Property instance at 0x1669476908>' 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. 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 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>
|
|
 |