Jump to content

Help with Python hierarchy syntax


BlackPariah

Recommended Posts

Hello! Python & programming newbie here having problems with syntax and hierarchy. I want to use... not sure what the right description is but: full function calls / paths with the complete path from root (hom module) to leaf (a method inside a class which is inside the hom module) In order to better visualize the hom module structure. The default Python SOP with the 2 starting lines "node = hou.pwd()"  and "geo = node.geometry()" creates some kind of typing shortcut and this hiding method might be good for seasoned programmers but for someone new like me it's confusing!

Sorry about the rant! Here is the basic task I'm trying to accomplish in the Python SOP.

1: Create a vector 3 variable

2: Create a point

3: Set new position of point with the created vector 3 variable

Here are the 3 terrible lines I tried to write:

position = hou.Vector3((5.0, 5.0, 5.0))

newpoint = hou.pwd().geometry().createPoint()

newpos = hou.pwd().point().setPosition(position)

 

Result: Python error: Traceback (most recent call last):
File "<stdin>", line 7, in <module>
AttributeError: 'SopNode' object has no attribute 'point'"

 

Q1: How do I fix the syntax here? 

Q2: Is there a better method of accomplishing the same thing in the Python SOP? (I'm aware VEX is better for data manipulation but this part of the process requires Python)  

 

**EDIT** Discovered the 2 problems (both in line 3). 1:Missing a self argument '0" in the point class's "setPosition" method/function. The Doc doesn't mention anything about this  argument requirement.

                                                                                    2:The full path of the point class is inside the geometry class but the Doc help has them listed side by side "hou.point" & "hou.geometry" without hierarchy consideration.

Here is the working 3 line code with full paths. Please let me know if there's any improvements or better methods 

position = hou.Vector3((5.0, 5.0, 5.0))

newpoint = hou.pwd().geometry().createPoint()

newpos = hou.pwd().geometry().point(0).setPosition(position)

 

Edited by BlackPariah
problem solved
Link to comment
Share on other sites

  • 3 weeks later...

Your last line could be simplified to newpoint.setPosition(position). Since you are storing the newly created point in a variable you can go straight and use all the hou.Point() functions. Print the newpoint variable and you'll see that it is a hou.Point() object. In this way you don't need the index of the point since this is stored in the newpoint variable already. 

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