Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
H3D.org Feeds


Browsing this Thread:   1 Anonymous Users






RuntimeError: UnableToCreatePythonField: fieldAsPythonObject()
#1
Not too shy to talk
Not too shy to talk


See User information
I am trying to work out the setValue() ' routing' approach, but this error keeps coming up.
Also, when I try updating the color of an object with self.dn["MAT"].diffuseColor.setValue(RGB(1,0,0)) for instance, the object does not change color.
I suspect that this error is the reason, but I can't figure out how to solve it. Here's the X3D:

<X3D
   <
Scene
      <!--
OBJECT--> 
      <
Shape
         <
Appearance
            <
Material DEF="MAT" diffuseColor="1 0 0"/> 
         </
Appearance
         <
Cylinder/> 
      </
Shape

      <
PythonScript DEF="PS" url="Trials.py"/>
   </
Scene>
</
X3D>


And the Python:

from H3DInterface import *

class 
Trial():
   
def __init__(self):
      
self.nodeself.dn createX3DNodeFromURL("Trials.x3d")
      
self.new_color RGB(010)
   
def update(self):
      
self.dn["MAT"].diffuseColor.setValue(self.changeColor())

   
def changeColor(self):
      return 
self.new_color

trial 
Trial()

def traverseSG():
   
trial.update()

Posted on: 5/10 11:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong Top


Re: RuntimeError: UnableToCreatePythonField: fieldAsPythonObject()
#2
Webmaster
Webmaster


See User information
It looks like you are mixing concepts a bit.

traverseSG is using the update function of the class Trial which kind of looks like an class that should inherit from the field types in H3DInterface and should be using the routing system.

Whichever system you are using ( traverseSG or the other setup with fields and routes) does not really matter but it was a bit confusing to me at first.

If this code is correct, then the first time traverseSG will be called the cylinder will change to the new color. Which color are you actually seeing when you start the program (maybe it changes so fast that you do not notice).

And finally, this really looks like some kind of recursive issue.
If your x3d file is called Trials.x3d then you can see that it includes the python script file Trials.py which then loads Trials.x3d which then loads Trials.py and I really do not know what to expect in this case (the module should only load once, but it is still quite weird).
You can either use the references field to give the node you are interested in to python or use getNamedNode() function in python.

Posted on: 5/14 9:10
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong Top







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create pdf.
You cannot get print page.

[Advanced Search]





(C) 2012 SenseGraphics AB    ---    Powered by XOOPS