Object Model question concerning points

   2031   2   0
User Avatar
Member
2 posts
Joined: Dec. 2007
Offline
I would like to create a script that given a curve SOP I can adjust their points' position in code but I can't figure out how to do it. Is there a way to do this? I tried the following code but I was getting a Geometry readonly error.

curve = hou.node('/obj/SampleCurve/curve1')
geo = curve.geometry()
pts = geo.points()
pt = pts
pt = pt + .01
pts.setPosition(pts,pt)
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
Geometry can only be manipulated through the Python Sop. The Geometry read error is a result of you attempting to access it through the python shell I would guess.

As to your actual code, there are a few things that are incorrect.

Everything is fine up to the end of 'pt = pts'. This as you would expect grabs the first point, as a hou.Point object.

The next line should error out because a Point object is unindexable.

In order to modify the point position you first must get the position as a vector.

pos = pt.position()

pos is now equivalent to hou.Vector4(#, #, #, #) depending on its position.

You can then manipulate these values and the set them back to modify the point position. For example, set the point to be on the XZ plane, Y=0

pos = 0

pt.setPosition(pos)

This allows you to modify any of the position values you'd like, then set them back nicely and give you the result you'd like. Once again it must happen in a Python Sop operator that has the ability to modify the geometry.
Graham Thompson, Technical Artist @ Rockstar Games
  • Quick Links