Inherit from a Softimage class

40 views
Skip to first unread message

Jeremie Passerin

unread,
Jul 10, 2012, 6:52:57 PM7/10/12
to softimage
Hi list, 

I'm pretty sure I know the answer to that one but just wondering. 
Do we have a way in Python to create a class that inherits from a class of the softimage SDK ? 

Let's say I want to extend the SIVector3 or the Null object ?

Any chance I could do something like that  ?

class mySIVector3( SIVector3 )
or 
class myCustomNull( Null )


Jeremie

jo benayoun

unread,
Jul 11, 2012, 3:10:09 PM7/11/12
to soft...@listproc.autodesk.com
Hey Jeremie,
considering the COM architecture (interfaces inheritance) + the python binding (dynamically invoking), this is really a bad idea to even think to inheritance...  The most easiest and elegant way that I think of is to wrap the desired object into a class.
On another hand, you're able to inherit some classes of the C++ API (even if its not recommended and limited) and create a python binding to it using the Python API.  Not even sure, you will get what you're looking for.
=(
-- Jo






2012/7/10 Jeremie Passerin <gere...@gmail.com>

Jeremie Passerin

unread,
Jul 12, 2012, 6:56:52 PM7/12/12
to soft...@listproc.autodesk.com
Thanks Jo, 

That was more a thinking I had rather than a real intention to do it... I'm looking for different way to organize my code. Thanks for the advice !

Chris Chia

unread,
Jul 12, 2012, 8:34:20 PM7/12/12
to <softimage@listproc.autodesk.com>
Will be interesting to see how u would implement that... Do share when you have something ;)

Chris

On 13 Jul, 2012, at 6:57 AM, "Jeremie Passerin" <gere...@gmail.com<mailto:gere...@gmail.com>> wrote:

Thanks Jo,

That was more a thinking I had rather than a real intention to do it... I'm looking for different way to organize my code. Thanks for the advice !

On 11 July 2012 12:10, jo benayoun <joben...@gmail.com<mailto:joben...@gmail.com>> wrote:
Hey Jeremie,
considering the COM architecture (interfaces inheritance) + the python binding (dynamically invoking), this is really a bad idea to even think to inheritance... The most easiest and elegant way that I think of is to wrap the desired object into a class.
On another hand, you're able to inherit some classes of the C++ API (even if its not recommended and limited) and create a python binding to it using the Python API. Not even sure, you will get what you're looking for.
=(
-- Jo







2012/7/10 Jeremie Passerin <gere...@gmail.com<mailto:gere...@gmail.com>>
winmail.dat

jo benayoun

unread,
Jul 15, 2012, 7:33:15 PM7/15/12
to soft...@listproc.autodesk.com
Hey Chris,
I assume you're referring to that part:
"you're able to inherit some classes of the C++ API [..]  and create a python binding to it using the Python API."

There is no magic.  Once you've inherited the desired class in cpp (in which the CBase is part of the inheritance tree), write your extension using the CPython API.  To provide a smoother inter-operability between both, I rely on the pythoncom lib and the XSI::ConvertObject function.

I'm not going to implement a complete subclass (too lazy on a sunday), but here is a sample that should show you the basic idea.  Note that I omitted any security code for brevity.  For other folks, don't use that in a production-context, it deserves much more love.

There could be some drawbacks depending on what is your usage as well as major differences between the two interfaces (C++ vs COM).  This is far from being *perfect* nor *elegant*, but still, I consider this mechanism valid for specific needs.
I would stay on my first suggestion for Jeremie tho, which is to wrap the desired class directly in python as it's also the way recommended by Mark Hammond himself according his book (he refers to it as the *delegate* pattern).

=)
-- Jo






2012/7/12 Chris Chia <chris...@autodesk.com>
Reply all
Reply to author
Forward
0 new messages