[x3d-public] Question about a Python and x3d.py Error message

John Carlson yottzumm at gmail.com
Wed Jan 15 09:36:05 PST 2025


I think the best thing to do is not have 2 parent classes.  An example of
converting with a DOM to an SAI tree is in X3DJSAIL (java):

https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/java/X3DLoaderDOM.html

If you find a way to convert DOM to SAI in python, I’m all ears.  I’ve
tried similar things with x3d.py without success:

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3dinput.py

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/cgx3djsonld.py

My recommendation is to study X3DJSAIL and try to do something like it.

Good luck!

John



On Wed, Jan 15, 2025 at 11:04 AM Bergstrom, Aaron via x3d-public <
x3d-public at web3d.org> wrote:

> Apparently, I’m a bit out of my depth when it comes to multi class
> inheritance. Not really a good tutorial out there for mixing inheritance
> from Maya python classes and other classes. I’m getting another error now.
>
> “'X3DScene' object has no attribute '_Scene__children'”
>
>
>
> Looking up similar errors in Google basically tells me I’m not calling the
> inherited classes __init__ methods.
>
>
>
> I’ll have to do some more digging.
>
>
>
> *From:* John Carlson <yottzumm at gmail.com>
> *Sent:* Wednesday, January 15, 2025 10:52 AM
> *To:* Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org
> >
> *Cc:* Bergstrom, Aaron <aaron.bergstrom at und.edu>
> *Subject:* Re: [x3d-public] Question about a Python and x3d.py Error
> message
>
>
>
> self is the first parameter to instance methods.  I don’t know about class
> methods.  My guess is you might want instance methods, but it’s your design.
>
>
>
> On Wed, Jan 15, 2025 at 10:37 AM Bergstrom, Aaron via x3d-public <
> x3d-public at web3d.org> wrote:
>
> John,
>
>
>
> Thanks for responding.
>
>
>
> So in the case of the code below, would the instance method be the “def
> creator(cls):” method? If so, would I think do the following: “def
> creator(cls, self):”
>
>
>
> Or am I not understanding what you are saying?
>
>
>
> Thanks,
>
>
>
> Aaron
>
>
>
> *From:* John Carlson <yottzumm at gmail.com>
> *Sent:* Wednesday, January 15, 2025 10:12 AM
> *To:* Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org
> >
> *Cc:* Bergstrom, Aaron <aaron.bergstrom at und.edu>
> *Subject:* Re: [x3d-public] Question about a Python and x3d.py Error
> message
>
>
>
> Aaron, AFAIK, you need “self” as the first parameter in your instance
> methods (not functions, of course).  I don’t know about class methods.
>
>
>
> If you’re familiar with Java or C++, this is similar to “this”.
>
>
>
> On Wed, Jan 15, 2025 at 10:02 AM Bergstrom, Aaron via x3d-public <
> x3d-public at web3d.org> wrote:
>
> I need help troubleshooting a x3d.py error message.
>
>
>
> In developing a Python version of the Rawkee X3D exporter plugin for Maya,
> I am attempting to create nodes that inherit from both the Maya Python API
> 2.0 and x3d.py
>
>
>
> As such, I have a question about python and multiple class inheritance,
> and an error I am seeing. Admittedly, I am not the strongest Python
> programmer.
>
>
>
> I am getting the following error when I execute the Python code in Maya,
> and I’m pretty sure I do not of the __init__() function setup correctly.
>
>
>
> # Error: TypeError: file C:\Users\user.name\AppData\Roaming\Python\Python311\site-packages\x3d\x3d.py
> line 14984: Scene.hasChild() missing 1 required positional argument: 'self'
> #
>
>
>
> Can anyone with some Python experience give me an idea of what I am doing
> wrong here?
>
>
>
> Here is the code:
>
> #################################################################
>
> import x3d
>
>
>
> import maya.api.OpenMaya as aom
>
> import maya.api.OpenMayaUI as aomui
>
> import maya.api.OpenMayaRender as aomr
>
>
>
> # import xmltodict
>
> # import json
>
>
>
> class X3DScene (aom.MPxNode, x3d.Scene):
>
>     TYPE_NAME    = "Scene"
>
>     TYPE_ID      = aom.MTypeId(0x00108FFF)
>
>     PROFILE_TYPE = "Full"
>
>     VERSION      = "4.0"
>
>
>
>     def __init__(self):
>
>         super(X3DScene, self).__init__()
>
>
>
>     @classmethod
>
>     def creator(cls):
>
>         return X3DScene()
>
>
>
>     @classmethod
>
>     def initialize(cls):
>
>         cls.x3dDoc = x3d.X3D(profile=cls.PROFILE_TYPE, version=cls.VERSION)
>
>         cls.x3dDoc.Scene = cls
>
>         #######################################################
>
>         # Test dump to make sure the class works as expected
>
>         #print(json.dumps(xmltodict.parse(cls.x3dDoc.XML()), indent=4))
>
>         print(cls.x3dDoc.XML())
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20250115/e1833e85/attachment.html>


More information about the x3d-public mailing list