I have a script that includes 2 functions to calculate distance between points. One is called euclid_d() and the other one is called manhattan_d()
At the moment, when I want to switch between the 2 functions I have to dive into the code, exchange the functions, and then run the script. How could I do that from the python SOP interface? Perhaps a drop-down menu? How is it done?
Couple of basic pyhton questions
26206 48 1- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
graham
You have somehow changed your parameter layout, through either the Edit Parameter Interface or through scripting. This causes this warning when you then try and modify your asset through the Type Properties.
Yes, I made the drop down menu. But I don't want this message to pop up everytime I run my Python code…
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
What kind of parameter values are you changing? The simple act of changing any parameter should be causing the operator to cook again. I'm pretty sure I've never had a problem like you are describing. Without seeing the operator I'm afraid I can't offer much in the way of suggestions.
If you want to force a node to cook you can bypass/unbypass it, or you could add a button that calls hou.pwd().cook()
If you want to force a node to cook you can bypass/unbypass it, or you could add a button that calls hou.pwd().cook()
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
I wanted to send you the otl, but for some reason it doesn't save the added parameters. (two floats, a and b, and a string).
What this does is: scale an attribute from a bottom value a to a top value b. A bit like the fit expression except that it gets the original max and min values automatically. The attribute name is supplied by a parameter.
Now, if I change the parameter, say the value a, then it doesn't recook.
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
att_name = hou.pwd().evalParm(“att_parm”)
a = hou.pwd().evalParm(“a_parm”)
b = hou.pwd().evalParm(“b_parm”)
print “Attribute”,att_name,“from a”,a,“ to b,”,b
attl = geo.findPointAttrib(att_name)
lst =
def read_att(attl):
for p in points:
pn = p.number()
lst.append(p.attribValue(attl))
return lst
#—————————————————-
def normList(lst, lower, upper):
print lower,upper
r = float(upper - lower) #the length of the interval
lstr = float(max(lst) - min(lst)) #the “length” of the list
lst = #make the list have the same “length” as the interval
diff = lower - min(lst) #calculate how “off” the list is
lst = #correct it
return lst
#—————————————-
def write_att(lst):
for p in points:
i = p.number()
value = normalized
p.setAttribValue(attl,value)
#****************RUN CODE*****************
lst = read_att(attl)
normalized = normList( lst, a, b)
write_att(normalized)
What this does is: scale an attribute from a bottom value a to a top value b. A bit like the fit expression except that it gets the original max and min values automatically. The attribute name is supplied by a parameter.
Now, if I change the parameter, say the value a, then it doesn't recook.
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
att_name = hou.pwd().evalParm(“att_parm”)
a = hou.pwd().evalParm(“a_parm”)
b = hou.pwd().evalParm(“b_parm”)
print “Attribute”,att_name,“from a”,a,“ to b,”,b
attl = geo.findPointAttrib(att_name)
lst =
def read_att(attl):
for p in points:
pn = p.number()
lst.append(p.attribValue(attl))
return lst
#—————————————————-
def normList(lst, lower, upper):
print lower,upper
r = float(upper - lower) #the length of the interval
lstr = float(max(lst) - min(lst)) #the “length” of the list
lst = #make the list have the same “length” as the interval
diff = lower - min(lst) #calculate how “off” the list is
lst = #correct it
return lst
#—————————————-
def write_att(lst):
for p in points:
i = p.number()
value = normalized
p.setAttribValue(attl,value)
#****************RUN CODE*****************
lst = read_att(attl)
normalized = normList( lst, a, b)
write_att(normalized)
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
Soothsayer
I wanted to send you the otl, but for some reason it doesn't save the added parameters. (two floats, a and b, and a string).
This is your problem and what I tried to say earlier. You added those parameters using the Edit Parameter Interface window as opposed to the Operator Type Properties. These parameters are spare parameters, not parameters belonging to the actual asset definition. This is why you receive the dialog when you hit Accept/Apply in the Type Properties. It wants to know what to do with your spare parameters. Spare parameter changes don't trigger recooking of the node.
To fix it all you want to remove the spare parameters, which you can do through the gear menu Edit Parameter Interface window, or by RMB on the labels of those parameters and choosing More>Delete Spare Parameter option. If you then add them back using the Operator Type Properties window for the asset all should be fine.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
Also, take a look at hou.Geometry.pointFloatAttribValues(). You can use it to replace your read/write att functions. pointFloatAttribValues() returns the attribute values for all the points in order into a single tuple without you having to iterate the points and append the value. It is significantly faster, especially when dealing with lots of points. Same goes with setPointFloatAttribValues().
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
Time for another basic python question. :wink:
I have the numpy module with my normal standard IDLE python and I'd like to import it inside Houdini pyhton. I tried putting the folder into houdini\scripts\python but that didn't work. (Maybe there is some stuff missing because numpy installs with an exe, so I'm not sure what kind of files it puts where)
So, how do I do that, on windows xp?
I have the numpy module with my normal standard IDLE python and I'd like to import it inside Houdini pyhton. I tried putting the folder into houdini\scripts\python but that didn't work. (Maybe there is some stuff missing because numpy installs with an exe, so I'm not sure what kind of files it puts where)
So, how do I do that, on windows xp?
--
Jobless
Jobless
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
I am trying to create points from a script running from the shelf but I get the message 'ObjNode' object has no attribute ‘createPoint’
obj = hou.node(“/obj”)
obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
geo = hou.node(“/obj/mypoints”)
dpoints={0:}
x = dpoints
y = dpoints
z = dpoints
point = geo.createPoint()
point.setPosition((x, y, z))
I think it's got something to do with not referring correctly to the innards of the node, but I'm not sure how to get it working. If it was in a SOP I'd use pwd(), but I am outside of it.
obj = hou.node(“/obj”)
obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
geo = hou.node(“/obj/mypoints”)
dpoints={0:}
x = dpoints
y = dpoints
z = dpoints
point = geo.createPoint()
point.setPosition((x, y, z))
I think it's got something to do with not referring correctly to the innards of the node, but I'm not sure how to get it working. If it was in a SOP I'd use pwd(), but I am outside of it.
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
You are trying to add points to an object node which doesn't make sense. You can only add points using HOM inside the cooking code of a Python SOP. If you want to generate points from a shelf tool you should create an Add SOP inside your geo container and plug your positions into the parms.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
To do it with an Add Sop you could do something like this:
dpoints={0:}
obj = hou.node(“/obj”)
container = obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
add = container.createNode(“add”)
add.parm(“usept0”).set(1)
add.parmTuple(“pt0”).set(dpoints)
dpoints={0:}
obj = hou.node(“/obj”)
container = obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
add = container.createNode(“add”)
add.parm(“usept0”).set(1)
add.parmTuple(“pt0”).set(dpoints)
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
Thanks Graham! You put me on the right track there.
For the record, if anybody needs to do something similar for a big dictionary containing points, this is how I did it:
import cPickle as pickle
pfile = file(“C:\points.txt”)
dpoints = pickle.load(pfile)
s=“”
for i in dpoints.keys():
pt = dpoints
pt = str(pt)
pt = pt.replace(“[”,“”)
pt = pt.replace(“]”,“ ”)
s = s+pt
obj = hou.node(“/obj”)
container = obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
add = container.createNode(“curve”)
add.parm(“coords”).set(s)
For the record, if anybody needs to do something similar for a big dictionary containing points, this is how I did it:
import cPickle as pickle
pfile = file(“C:\points.txt”)
dpoints = pickle.load(pfile)
s=“”
for i in dpoints.keys():
pt = dpoints
pt = str(pt)
pt = pt.replace(“[”,“”)
pt = pt.replace(“]”,“ ”)
s = s+pt
obj = hou.node(“/obj”)
container = obj.createNode(“geo”, “mypoints” , run_init_scripts=False)
add = container.createNode(“curve”)
add.parm(“coords”).set(s)
--
Jobless
Jobless
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
-
- Quick Links