What is wrong with this python codes?

   2425   1   0
User Avatar
Member
7 posts
Joined: 2月 2010
Offline
I want to make python node for acumulative color from attrib transfer SOP(Cd) to some object.

I don't know what is problem.
——————————————————
thisnode = hou.pwd()
inputs = thisnode.inputs()

first_input_geo = inputs.geometry()
first_input_points = first_input_geo.points()

second_input_geo = inputs.geometry()
second_input_points = second_input_geo.points()

this_geo=thisnode.geometry()
this_points=this_geo.points()

fi_cr = first_input_points.attribValue('Cd')
si_cr = second_input_points.attribValue('Cd')
this_cr = this_points.attribValue('Cd')


impulse_flag_attrib = this_points.addAttrib(hou.attribType.Point,“impulse_flag”,0)

if si_cr != fi_cr:
this_points.setAttribValue(impulse_flag_attrib, 1)
this_points.setAttribValue(this_cr, si_cr)
else:
this_points.setAttribValue(impulse_flag_attrib, impulse_flag_attrib)
if impulse_flag_attrib == 1:
this_points.setAttribValue(this_cr, this_cr)
——————————————

Attachments:
zz1.jpg (98.8 KB)

User Avatar
Member
1922 posts
Joined: 11月 2006
Offline
Looks to me like there are actually several problems with the code. One problem is your syntax when you are trying to get the red values from your points. You are attempting to call attribValue() on a tuple of points, not on an actual point. first_input_points is a tuple and does not have any function called attribValue(). Later when you try and set the attribute value you are once again trying to set a value on a tuple. To do what you are trying to do you'll need to iterate over all the points and call the functions on each of those points. You also need to add the point attribute to the geometry, not the points tuple.

Also looking at your if statement where you have the logic to assign values I'm pretty confused as to what you are trying to set because the syntax is really wrong and doesn't make sense. setAttribValue() takes a hou.Attrib or an attribute name as the first parameter and the value to set as the second. One time you have it rightish but then other times you try passing 2 values or 2 attribute pointers so I'm not sure exactly what you are going for. Here's a way that should work but you'll have to figure out the last part:

thisnode = hou.pwd()
inputs = thisnode.inputs()

first_input_geo = inputs.geometry()
first_input_points = first_input_geo.points()

second_input_geo = inputs.geometry()
second_input_points = second_input_geo.points()

this_geo=thisnode.geometry()
this_points=this_geo.points()

impulse_flag_attrib = this_geo.addAttrib(hou.attribType.Point,“impulse_flag”,0)

for point, fpoint, spoint in zip(this_points, first_input_points, second_input_points):
fi_cr = fpoint.attribValue('Cd')
si_cr = spoint.attribValue('Cd')
this_cr = point.attribValue('Cd')

if si_cr != fi_cr:
# do something like point.setAttribValue(impulse_flag_attr, fi_cr + si_cr)
else:
# this will cause a syntax error
this_points.setAttribValue(impulse_flag_attrib, impulse_flag_attrib)
# impulse_flag_attrib does not have a value, it is a reference to an attribute on the
# geometry so not sure what you are going for here.
if impulse_flag_attrib == 1:
this_points.setAttribValue(this_cr, this_cr)
Graham Thompson, Technical Artist @ Rockstar Games
  • Quick Links