thinkinmonkey Posted February 28, 2010 Share Posted February 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted March 1, 2010 Share Posted March 1, 2010 (edited) 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 March 1, 2010 by SWANN Quote Link to comment Share on other sites More sharing options...
thinkinmonkey Posted March 1, 2010 Author Share Posted March 1, 2010 (edited) 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! 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 March 1, 2010 by thinkinmonkey Quote Link to comment Share on other sites More sharing options...
thinkinmonkey Posted March 1, 2010 Author Share Posted March 1, 2010 Quote Link to comment Share on other sites More sharing options...
graham Posted March 1, 2010 Share Posted March 1, 2010 (edited) 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 -> %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 March 1, 2010 by graham Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted March 1, 2010 Share Posted March 1, 2010 Thant cool, thanks Graham. Quote Link to comment Share on other sites More sharing options...
thinkinmonkey Posted March 2, 2010 Author Share Posted March 2, 2010 Graham, really thanks for explanation and solutions: now it works flawlessly without adding attribCreate node! Really thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.