I'm new to this python stuff so excuse me if these are a bit dumb.
-Often, in the hou help docs methods require a self. What does this stand for and how do I refer to it?
-How do I know what node parameters I can access? Is there a list of this (like the details view)?
Couple of basic pyhton questions
26207 48 1- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
Self is like the Python term for this. Just a reference to the particular instance of a class. You only really need to care about it when you are writing your own classes so you can basically ignore it.
Parameters are straight forward using hou.Node.parm(), hou.Node.parmTuple(), etc… but I get the feeling you mean attributes since you are talking about the Detail view. You can find all the attributes that exist through functions of hou.Geometry.
Parameters are straight forward using hou.Node.parm(), hou.Node.parmTuple(), etc… but I get the feeling you mean attributes since you are talking about the Detail view. You can find all the attributes that exist through functions of hou.Geometry.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
Hm. Ok. I'm trying to find my way around this.
As for the parameters, I think they are listed in the parameter interface. Logic, but I never really thought of it. ops:
What I want to do is run some algorithms on attributes via a python sop.
There seem to be many ways to get at attribute data. I would like to get an already existing attribute as a list. Whatever method I look at always leads me back to hou.Attrib or some other method that just returns individual point attrib values. So, I have to write a loop to get at the data (as a list) or is there a specific function?
As for the parameters, I think they are listed in the parameter interface. Logic, but I never really thought of it. ops:
What I want to do is run some algorithms on attributes via a python sop.
There seem to be many ways to get at attribute data. I would like to get an already existing attribute as a list. Whatever method I look at always leads me back to hou.Attrib or some other method that just returns individual point attrib values. So, I have to write a loop to get at the data (as a list) or is there a specific function?
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
Ok, I almost got it. I can now read attributes with
hou.pwd().geometry().pointFloatAttribValues(“attr”)
mess with them (I can print them and they look ok) , but I can't write them with
hou.pwd().geometry().SetPointFloatAttribValues(“attr”, computedstuff)
Why would that be? Maybe it is that self thing again. I dunno what to do with it.
hou.pwd().geometry().pointFloatAttribValues(“attr”)
mess with them (I can print them and they look ok) , but I can't write them with
hou.pwd().geometry().SetPointFloatAttribValues(“attr”, computedstuff)
Why would that be? Maybe it is that self thing again. I dunno what to do with it.
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
hou.Geometry.points() is just giving you a tuple of objects, in this case hou.Point objects. The tuple itself is just an immutable list and has nothing to do with whatever is in it. You need to iterate over the elements in it.
ppoints = hou.pwd().geometry().points()
for point in ppoints:
point.position()
ppoints = hou.pwd().geometry().points()
for point in ppoints:
point.position()
Graham Thompson, Technical Artist @ Rockstar Games
- mark
- Staff
- 2590 posts
- Joined: July 2005
- Offline
graham
hou.Geometry.points() is just giving you a tuple of objects, in this case hou.Point objects. The tuple itself is just an immutable list and has nothing to do with whatever is in it. You need to iterate over the elements in it.
ppoints = hou.pwd().geometry().points()
for point in ppoints:
point.position()
Or
ppoints.position()
to get the position of point 3.
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
mark
Or
ppoints.position()
to get the position of point 3.
Also, if you have lots of points or prims and you want random access rather than straight iteration you can use hou.Geometry.iterPoints() or iterPrims(). This has the advantage of not having to allocate all the hou.Point objects and provides a generator that is very fast at random access into the points/prims. If you want most or all of the elements though, points() or prims() will probably be better.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
geo.pointFloatAttribValues(“P”) gives you a tuple of floats whereas geo.points() gives you a tuple of hou.Point objects.
In the first case you are just getting raw numbers and the other you are getting objects that you can then use to extract other information.
In the first case you are just getting raw numbers and the other you are getting objects that you can then use to extract other information.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
I have 3 more simple questions:
-I made a python SOP but it doesn't run the code unless I open Type Properties and hit Apply. Can I make it run automatically
-That very same SOP keeps telling me that “Some instances of ”New Operator“ have had their parameter layout modified…blablablabla” and then gives me 3 options “No changes” “Revert Layout” and “Destroy All Spare Paramaters”
-How can I include the SOP with the code into the hip file. At the moment it resides somewhere else and gets lost when I transfer the hip to another computer.
-I made a python SOP but it doesn't run the code unless I open Type Properties and hit Apply. Can I make it run automatically
-That very same SOP keeps telling me that “Some instances of ”New Operator“ have had their parameter layout modified…blablablabla” and then gives me 3 options “No changes” “Revert Layout” and “Destroy All Spare Paramaters”
-How can I include the SOP with the code into the hip file. At the moment it resides somewhere else and gets lost when I transfer the hip to another computer.
--
Jobless
Jobless
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
When you hit Apply/Accept it makes a change to the operator type and that causes it to recook. It should recook when the input geometry changes, you bypass then unbypass, load the hip file, if the frame changes and it is time dependent, etc. Without seeing it I can't really say why it might not be cooking.
Have you somehow modified the parameter layout of your operator? If you'd done something to the parameters through the Edit Parameter Interface window, or through scripting then it will give you that warning.
If you want to include the SOP in the hip file then you need to save a copy of the definition in the Embedded section of the hip file and make sure to use that definition.
Have you somehow modified the parameter layout of your operator? If you'd done something to the parameters through the Edit Parameter Interface window, or through scripting then it will give you that warning.
If you want to include the SOP in the hip file then you need to save a copy of the definition in the Embedded section of the hip file and make sure to use that definition.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
To save an asset as Embedded all you have to do is type Embedded as the file name.
If you have an existing asset you wish to embed, RMB on the node and select Operator Type Manager and then RMB on the definition and choose Copy. In the dialog that pops up you can change the path to Embedded and hit Accept. If you now look under the Current HIP File tree in the list you should see an Embedded section with your asset definition inside. RMB on it and choose Use This Definition. Your scene is now preferring this definition and it is saved into the file.
Of course any changes you make to the file on disk won't effect this embedded one.
If you have an existing asset you wish to embed, RMB on the node and select Operator Type Manager and then RMB on the definition and choose Copy. In the dialog that pops up you can change the path to Embedded and hit Accept. If you now look under the Current HIP File tree in the list you should see an Embedded section with your asset definition inside. RMB on it and choose Use This Definition. Your scene is now preferring this definition and it is saved into the file.
Of course any changes you make to the file on disk won't effect this embedded one.
Graham Thompson, Technical Artist @ Rockstar Games
- Soothsayer
- Member
- 856 posts
- Joined: Oct. 2008
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Offline
The most straightforward way of getting all the instance of an operator type is to use hou.NodeType.instances()
For example, to get all the instances of the Object/null you can do:
node_type = hou.nodeType(hou.objNodeTypeCategory(), “null”)
instances = node_type.instances()
This will give you all the Object level Nulls in the scene.
The alternative to this of course is to recursively traverse the scene hierarchy looking for nodes that match your specific type.
For example, to get all the instances of the Object/null you can do:
node_type = hou.nodeType(hou.objNodeTypeCategory(), “null”)
instances = node_type.instances()
This will give you all the Object level Nulls in the scene.
The alternative to this of course is to recursively traverse the scene hierarchy looking for nodes that match your specific type.
Graham Thompson, Technical Artist @ Rockstar Games
-
- Quick Links