[x3d-public] x3d.py, X3dToPython.xslt issues

John Carlson yottzumm at gmail.com
Sat Jul 24 00:56:50 PDT 2021


The below error was fixed by setting PYTHONPATH=x3d, per the ant script.
> This appears to be a common issue.  I don't know a patch at this time.
>
>
> $ python x3domflowers.py
> Traceback (most recent call last):
>   File "x3domflowers.py", line 21, in <module>
>     from x3d import *
> AttributeError: module 'x3d' has no attribute 'SFBool'


Here's another puzzler:


$ python3 !$
python3 examples/x3domflowers.py
x3d.py package loaded, have fun with X3D Graphics!
Traceback (most recent call last):
   File "examples/x3domflowers.py", line 44, in <module>
     ProtoDeclare(name='flower',
   File "/c/x3d-code/www.web3d.org/x3d/stylesheets/python/x3d/x3d.py", 
line 9724, in __init__
     self.ProtoBody = ProtoBody
   File "/c/x3d-code/www.web3d.org/x3d/stylesheets/python/x3d/x3d.py", 
line 9765, in ProtoBody
     if not ProtoBody is None and not 
isinstance(ProtoBody,(ProtoBody,ProtoInstance)):
TypeError: isinstance() arg 2 must be a type or tuple of types


Code is below, generated by X3dToPython.xslt  More Proto examples 
needed, perhaps.

=====================================================


###############################################
#
# Now available: developmental python x3d.py package on PyPi for import.
#   This approach greatly simplifies Python X3D deployment and use.
#   https://pypi.org/project/x3d
#
# Installation:
#       pip install x3d
# or
#       python -m pip install x3d
#
# Developer options for loading x3d package:
#
#    from x3d import *  # preferred approach, terser source that avoids 
x3d.* class prefixes
#
# or
#    import x3d         # traditional way to subclass x3d package, all 
classes require x3d.* prefix
#                       # but python source is very verbose, for example 
x3d.Material x3d.Shape etc.
#                       # X3dToPython.xslt stylesheet 
insertPackagePrefix=true supports this option.

from x3d import *

###############################################

newModel=X3D(profile='Immersive',version='3.3',
   head=head(
     children=[
     meta(name='title',content='x3domflowers.x3d'),
     meta(name='creator',content='John Carlson'),
     meta(name='description',content='5 or more prismatic flowers'),
     meta(name='generator',content='X3D-Edit, 
https://savage.nps.edu/X3D-Edit'),
meta(name='identifier',content='https://coderextreme.net/X3DJSONLD/src/main/data/x3domflowers.x3d')]),
   Scene=Scene(
     children=[
     NavigationInfo(),
     #  Images courtesy of Paul Debevec's Light Probe Image Gallery
Background(backUrl=["../resources/images/all_probes/stpeters_cross/stpeters_back.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_back.png"],bottomUrl=["../resources/images/all_probes/stpeters_cross/stpeters_bottom.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_bottom.png"],frontUrl=["../resources/images/all_probes/stpeters_cross/stpeters_front.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_front.png"],leftUrl=["../resources/images/all_probes/stpeters_cross/stpeters_left.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_left.png"],rightUrl=["../resources/images/all_probes/stpeters_cross/stpeters_right.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_right.png"],topUrl=["../resources/images/all_probes/stpeters_cross/stpeters_top.png","https://coderextreme.net/X3DJSONLD/images/all_probes/stpeters_cross/stpeters_top.png"]),
     Group(
       children=[
ExternProtoDeclare(name='FlowerProto',url=["../data/flowerproto.json#FlowerProto"],
         field=[
field(accessType='inputOutput',name='vertex',type='MFString'),
field(accessType='inputOutput',name='fragment',type='MFString')]),
       ProtoDeclare(name='flower',
         ProtoBody=ProtoBody(
           children=[
           Group(
             children=[
             ProtoInstance(name='FlowerProto',
               fieldValue=[
fieldValue(name='vertex',value=["../shaders/x3dom_flowers_chromatic.vs"]),
fieldValue(name='fragment',value=["../shaders/common.fs"])])])])),
       ProtoInstance(name='flower'),
       ProtoInstance(name='flower'),
       ProtoInstance(name='flower'),
       ProtoInstance(name='flower'),
       ProtoInstance(name='flower'),
       ProtoInstance(name='flower')])])
) # X3D model complete

###############################################
# Self-test diagnostics
###############################################

if        metaDiagnostics(newModel): # built-in utility method in X3D class
     print(metaDiagnostics(newModel))
print('check  newModel.XML() serialization...')
newModelXML = newModel.XML() # test export method XML() for exceptions
# print(newModelXML) # debug

print ("python x3d.py load successful for x3domflowers.py")





More information about the x3d-public mailing list