samboosa Posted February 17, 2013 Share Posted February 17, 2013 Hello, I'm trying to learn python but of all the documentation I've read I'm still not sure where to start... So I have a set of points which make up a shape, what I want to do is duplicate them upwards and then add various other attributes. # This code is called when instances of this SOP cook.node = hou.pwd()geo = node.geometry()# Add code to modify the contents of geo.#Dimensions and offset of incoming geoheight = 0xoffset = hou.hscriptExpression("$CEX")zoffset = hou.hscriptExpression("$CEZ")#Refer to the parameter interfacelevels = hou.pwd().evalParm("Levels")level_height = hou.pwd().evalParm("Level_height")attrib_name = hou.pwd().evalParm("attrib_name")#Add attributesattrib = geo.addAttrib(hou.attribType.Point, attrib_name, 1)#The functionfor point in geo.points(): for i in range(0,levels): point = geo.createPoint() x_pos = float(xoffset) y_pos = float(height) z_pos = float(zoffset) point.setPosition((0,y_pos+level_height*i,0))[/CODE]My problem is at "point.setPosition((0,y_pos+level_height*i,0))" - this translates the copied points upwards, but I don't know how do do this from the original position instead of setting their position to the origin.Any help would be greatly appreciated!- Samboosa. Quote Link to comment Share on other sites More sharing options...
symek Posted February 17, 2013 Share Posted February 17, 2013 (edited) pos = point.position() + hou.Vector3((0, y_pos+level_height*i, 0))point.setPosition(pos)[/CODE]also, you may consider:[CODE]centroid = geo.boudingBox().center()[/CODE]for $CEX, $CEZ Edited February 17, 2013 by SYmek Quote Link to comment Share on other sites More sharing options...
samboosa Posted February 18, 2013 Author Share Posted February 18, 2013 Thank you SYmek for your reply, unfortunately I'm still getting the same result; all the points are in the center. I think the problem is the fact that I'm creating points for every point of the input geometry, but from the initial point creation I'm not setting them to the location of the original points. Quote Link to comment Share on other sites More sharing options...
samboosa Posted February 18, 2013 Author Share Posted February 18, 2013 (edited) Thank you again SYmek, I fixed the problem simply by reordering my code for i in range(0,levels):for point in geo.points(): x_pos = float(xoffset) y_pos = float(height) z_pos = float(zoffset) pos = point.position() + hou.Vector3((0, y_pos+level_height*i,0)) point = geo.createPoint() point.setPosition(pos)[/CODE]In my second code iteration I decided I didn't even need the centroid position, the code that gives me what I want is:[CODE]for point in geo.points(): for i in range(0,levels): pos = point.position() + hou.Vector3((0, level_height,0)) point = geo.createPoint() point.setPosition(pos)[/CODE] Edited February 18, 2013 by samboosa 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.