Jump to content

Copying points Python SOP


samboosa

Recommended Posts

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 geo
height = 0
xoffset = hou.hscriptExpression("$CEX")
zoffset = hou.hscriptExpression("$CEZ")
#Refer to the parameter interface
levels = hou.pwd().evalParm("Levels")
level_height = hou.pwd().evalParm("Level_height")
attrib_name = hou.pwd().evalParm("attrib_name")
#Add attributes
attrib = geo.addAttrib(hou.attribType.Point, attrib_name, 1)
#The function
for 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.

Link to comment
Share on other sites

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.

post-8196-0-39187100-1361183997_thumb.jp

Link to comment
Share on other sites

Thank you again SYmek, I fixed the problem simply by reordering my code :D


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]

post-8196-0-07059600-1361186750_thumb.jp

Edited by samboosa
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...