[x3d-public] Question about a Python and x3d.py Error message
Bergstrom, Aaron
aaron.bergstrom at und.edu
Wed Jan 15 12:23:09 PST 2025
All,
Quick follow up. Apparently, I all I needed to do to fix the error was to add line 3 to my code as shown below. The error has now gone away.
1 def __init__(self):
2 super(X3DScene, self).__init__()
3 x3d.Scene.__init__(self)
@John – thanks for the feedback. You’re first message is what helped me look for the right answer.
So using the following postContructor method in my Maya/X3D.py Franken Node…
def postConstructor(self):
self.x3dDoc = x3d.X3D(profile=self.PROFILE_TYPE, version=self.VERSION)
self.x3dDoc.Scene = self
self.children.append(x3d.Transform())
print(self.x3dDoc.XML())
…I generated the following X3D Markup:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "https://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Full' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
<Scene>
<Transform/>
</Scene>
</X3D>
The Maya ‘Scene’ node seems to be working just fine. And the X3D text is generated as expected.
So I guess it’s all good.
Thanks everyone!
Aaron
From: x3d-public <x3d-public-bounces at web3d.org> On Behalf Of Bergstrom, Aaron via x3d-public
Sent: Wednesday, January 15, 2025 2:02 PM
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
All,
My problem is that I want to be fancy and use as much of the existing Maya toolset as possible so as to not force Maya users to change their workflows in order to use the exporter.
I’m already walking the Maya scene graph and generating X3D code from it using x3d.py, but I was really hoping to using the spiffy Maya Node Editor to do scripting/routing.
At the end of the day yesterday I had what I thought was an epiphany in that I could use the Node Editor to do that if I embedded x3d.py objects in Maya custom nodes.
So far, Maya seems to tolerate the multi inheritance just fine when I create custom nodes from multi inheritance classes, but it just that I seem to be throwing python code errors whenever I try to manipulate the X3D scenegraph. And from what I can tell, I’m just not calling the properly calling __init__ for multiple inheritance.
That said, I’m all for re-using code. And if you don’t mind me borrowing some of that code as long as I give everyone proper credit, I’ll probably snatch some of it as needed.
@Don – I apologize for being creative.
😃
Of course, I’m no Python programmer, so I may just be wasting my time trying to force the use of the Maya Node Editor.
Aaron
From: x3d-public <x3d-public-bounces at web3d.org<mailto:x3d-public-bounces at web3d.org>> On Behalf Of John Carlson via x3d-public
Sent: Wednesday, January 15, 2025 11:43 AM
To: Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Cc: John Carlson <yottzumm at gmail.com<mailto:yottzumm at gmail.com>>
Subject: Re: [x3d-public] Question about a Python and x3d.py Error message
The issue is, I think, that Aaron has some kind of internal structure (DOM?) that he wants to convert to a x3d.py structure. He can create python and then run it separately, or try to instantiate x3d.py classes in his code.
I’m not saying this is a great approach, but you can look at Doug and my code for exporting from Blender.
https://github.com/coderextreme/BlenderX3DSupport/blob/main/io_scene_x3dv/blender/exp/x3dv_blender_export.py
I’ve move back to constructing strings for now.
John
On Wed, Jan 15, 2025 at 11:25 AM Brutzman, Donald (Don) (CIV) via x3d-public <x3d-public at web3d.org<mailto:x3d-public at web3d.org>> wrote:
Hey guys, "please don't go there." You should never need to poke around with __init__ or inheritance or any of that internal stuff. Those code patterns are autogenerated, so you don't have to do any of that.
Just build a scene graph. The vocabulary is simply X3D.
Corrolary: "creativity is punished" 😨
all the best, Don
--
Don Brutzman Naval Postgraduate School, Code USW/Br brutzman at nps.edu<mailto:brutzman at nps.edu>
Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149
X3D graphics, virtual worlds, navy robotics https://faculty.nps.edu/brutzman
________________________________
From: x3d-public <x3d-public-bounces at web3d.org<mailto:x3d-public-bounces at web3d.org>> on behalf of Bergstrom, Aaron via x3d-public <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Sent: Wednesday, January 15, 2025 9:03 AM
To: Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Cc: Bergstrom, Aaron <aaron.bergstrom at und.edu<mailto:aaron.bergstrom at und.edu>>
Subject: Re: [x3d-public] Question about a Python and x3d.py Error message
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<mailto:yottzumm at gmail.com>>
Sent: Wednesday, January 15, 2025 10:52 AM
To: Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Cc: Bergstrom, Aaron <aaron.bergstrom at und.edu<mailto: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<mailto: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<mailto:yottzumm at gmail.com>>
Sent: Wednesday, January 15, 2025 10:12 AM
To: Extensible 3D (X3D) Graphics public discussion <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Cc: Bergstrom, Aaron <aaron.bergstrom at und.edu<mailto: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<mailto: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<http://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<mailto:x3d-public at web3d.org>
http://web3d.org/mailman/listinfo/x3d-public_web3d.org
_______________________________________________
x3d-public mailing list
x3d-public at web3d.org<mailto:x3d-public at web3d.org>
http://web3d.org/mailman/listinfo/x3d-public_web3d.org
_______________________________________________
x3d-public mailing list
x3d-public at web3d.org<mailto: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/62ca9803/attachment-0001.html>
More information about the x3d-public
mailing list