Jump to content

Python, addAttrib and Copy/Stamp


thinkinmonkey

Recommended Posts

Hi all,

my purpose is a python SOP node with a ramp that controls positions of points and assign them keys' values.

The code I wrote is this:

# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()

radiusAttrib = geo.addAttrib(hou.attribType.Point, "radius", 0.0)

x1 = 0.0
y1 = 0.0
z1 = 0.0

ramp = hou.Node.evalParm(hou.pwd(), "ramp")
keys = ramp.keys()
values = ramp.values()

i = 0

# Add code to modify the contents of geo.
for pt in geo.points():
    newpos = (x1, keys[i], z1)
    pt.setPosition(newpos)
    pt.setAttribValue(radiusAttrib, values[i])
    i += 1

Ok, quite simple!

Now I have radius attrib for all points, I can see it in Details view, but when I try to use that attrib with copy/stamp tecnique, I had the error the node is not able to evaluate expression!

I put on "Use Template Point Attributes", the "Stamp Input" is on, the valus is "$RADIUS", but nothing!

Do you have some solution?

Thanks in advance.

P.S. I'm attaching the test scene and the operator, but the operator is not in the same dir of the scene, so I don't know if you'll have trouble with it, anyway, the code is the same of above.

worm.hipnc

thm_Ramp2Line.otl

Link to comment
Share on other sites

Guest Swann

Just quick look.

You try to use $RADIUS but it's local name and you don't have local variable. Your attribute is just called RADIUS. In file you used uppercase while in your post it's lowercase. So to acces it use point() expression.

BTW: From when we can see local names of attributes in DetailView ? ;)

Edited by SWANN
Link to comment
Share on other sites

I think to have solved the problem, but it's an half solution! <_<

I have to put an attribCreate SOP just before the python node wich it has only to put values on that "radius" attribute previously created.

But it still remains doubts why addAttrib doesn't work in the same manner of attribCreate!

Any suggestion is highly appreciated!

OLD:

Hi Swann,

my problem is why the addAttrib/setAttrib python functions don't work in the same way of a attribCreate SOP node!

post-2959-12674470235_thumb.jpgpost-2959-126744701597_thumb.jpg

The strange fact is while the attribCreate works perfectly (i.e. the radius attribute is cooked), my node creates troubles even if it's shown regularly in Details View.

I've tried to change lowercase/uppercase in order to find a solution, but with no success.

So, you say I have to use point() expression, but do you mean in the value field of copy node?

Is this the expression you say Point() on online doc ?

Thanks

Edited by thinkinmonkey
Link to comment
Share on other sites

So as you've seen the addAttrib() function doesn't create local variables. There is an existing RFE for addAttrib() to be able to create the local variable.

You can however do it yourself fairly easily by inserting a mapping into the varmap, or creating it if it does not exist. If you add the following code to your operator you should be good.

map_val = "%s -&gt; %s" % (radiusAttrib.name(), radiusAttrib.name().upper())
if geo.findGlobalAttrib("varmap") is None:
    geo.addAttrib(hou.attribType.Global, "varmap", "")
geo.setGlobalAttribValue("varmap", map_val)

Since the varmap attribute is just a string (index) attribute, you can just add new strings to it by using the setGlobalAttribValue() function. This in essence appends an entry to the list and allows you to add a new mapping without distorting the original mappings.

Edited by graham
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...