pclaes Posted February 22, 2008 Share Posted February 22, 2008 Hi guys, I came across a little problem and I am trying to get through it with python. I have experience with scripting but not with python in houdini. I have to convert a polygon curve to a nurbs curve, but... the polygon points need to be used as breakpoints (curve points), not as Cv's. The only way I see of doing it is of attaching a "curve sop" to the polygon curve. But the curve sop takes a string as input which is like: "x1,y1,z1 x2,y2,z2 x3,y3,z3 x4,y4,z4 ...." so basically it takes in the translation values of each point. I need to generate that string. I am currently looking into python as it seems like a simple for-loop and in mel I would write it a bit like: string result = ""; for( i=0, i < $NPT, i++) { result += getTranslateX + "," ; result += getTranslateY + "," ; result += getTranslateZ + "," ; result += " "; } return result; So far I got an new python sop that does: geo = hou.pwd().geometry() pos_string = geo.addAttrib(hou.attribType.Point, "posString", "") for point in geo.points(): print point.position() Now I think it would be best to store the resulting string on the "detail" level rather then on point, but I haven't figured that out yet. Also I find navigating the help files not that easy (as in Maya), but that is probably because I am not used to it yet. thanks for any help! Peter Quote Link to comment Share on other sites More sharing options...
graham Posted February 22, 2008 Share Posted February 22, 2008 (edited) To get the positions into a string you just need to do: result = "" for point in geo.points(): result += str(point.position()[0]) + ',' result += str(point.position()[1]) + ',' result += str(point.position()[2]) + ' ' geo.addAttrib(hou.attribType.Global, "posString", "") geo.setGlobalAttribValue("posString", result) Detail attributes are referred to as Global attributes in HOM. Edited February 22, 2008 by graham Quote Link to comment Share on other sites More sharing options...
petz Posted February 22, 2008 Share Posted February 22, 2008 you can also use point numbers as input for the curve sop like p0 p1 p2 .... just put down a partition sop and use p$PT as rule, so you poly_to_nurbs.hipnc Quote Link to comment Share on other sites More sharing options...
pclaes Posted February 23, 2008 Author Share Posted February 23, 2008 Thanks guys !! I'll try it out asap. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted February 24, 2008 Share Posted February 24, 2008 Try the fit sop Quote Link to comment Share on other sites More sharing options...
rdg Posted February 24, 2008 Share Posted February 24, 2008 to complete the list: you could also group all or a subset of the points with a groupSOP and use this expression to generate the string: ` Quote Link to comment Share on other sites More sharing options...
pclaes Posted February 24, 2008 Author Share Posted February 24, 2008 thanks again ! I have tried out all solutions and they are all very interesting! I love some of the creative expression use! Never though of using the partition sop as a way of generating a string and not actually using the groups, just their names. The fit operator works too, but gives slightly different results. rdg: that is some very cool name linking, it took me a bit to figure out your expression but using opinput(".", 0) to refer to the previous node and combining it with $OS to get to that group is a very nice way! I've put all these different solutions in one file for my own personal future reference. I thought I attach it so other people can learn from this if they come across similar challenge. python_curve_string_01.hip Quote Link to comment Share on other sites More sharing options...
JoshJ Posted May 15, 2008 Share Posted May 15, 2008 Hi Peter, I tried loading up your file and I'm getting this error message for the curve_test1 sop: # Couldn't find Python code. Please check that # oplib:/Sop/curve_test?Sop/curve_test.py is in the proper location. thanks again !I have tried out all solutions and they are all very interesting! I love some of the creative expression use! Never though of using the partition sop as a way of generating a string and not actually using the groups, just their names. The fit operator works too, but gives slightly different results. rdg: that is some very cool name linking, it took me a bit to figure out your expression but using opinput(".", 0) to refer to the previous node and combining it with $OS to get to that group is a very nice way! I've put all these different solutions in one file for my own personal future reference. I thought I attach it so other people can learn from this if they come across similar challenge. 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.