Jump to content

how to reorder points in python?


kuaile_yzh

Recommended Posts

guys,i meet a afflicting puzzle,anybody can do me a favor?

I just have a more stupid way:exchange all positions of all points,then exchange their attributes.

this method is troublesome and low-cost,i wonder if anyone can have a more convenient way.

thx.

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

# Add code to modify the contents of geo.
tempos=[]
temattrib=[]
for point in geo.points():
	tempos.append(point.position())
	temattrib.append(point.attribValue("Cd"))
pnum=len(tempos)
a=0
for i in range(pnum):
	geo.points()[a].setPosition(tempos[pnum-1])
	geo.points()[a].setAttribValue("Cd",temattrib[pnum-1])
	pnum-=1
	a+=1

sort02.hipnc

Edited by kuaile_yzh
Link to comment
Share on other sites

hello. I am new to houdini and am a little confused. Is this a script sop ? In the docs it says that the script sop does not modify the geometry. I was looking through the docs and the only type of sop I could find to edit the geometry in a similar manner would be a vop sop or a vex sop. Please enlighten me,

thanks

-ranxx

just change the index of the point but keep its attribute.thx.
Link to comment
Share on other sites

I just have a more stupid way:exchange all positions of all points,then exchange their attributes.

this method is troublesome and low-cost,i wonder if anyone can have a more convenient way.

I was going to say, just use the Sort SOP but you already have that in your .hip file so I am not sure what your question is? By the way, your .hip file wasn't saved with Embedded definitions so your Python SOP code was not included.

Link to comment
Share on other sites

You just effectively did that in python. Points (and attributes) are stored as arrays in Houdini. $PT, or point number is just the index into these arrays. If you want to make your python code more "efficient", then instead of doing two loops, just do one loop and swap half of the elements.

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...