Houdini PyTake2

HouPyTake2 is a Python wrapper around the Hscript commands to create and edit Houdini’s takes. You can create and edit takes, include or remove node(s) or parameter(s) as well as flags.

No support will be provided anymore on that script, Houdini has now an python API for takes: hou.takes

Compatibility: Houdini 14, 15, 15.5, 16, 16.5, 17.0

Install

Just copy the PyTake2.py file into your $PYTHONPATH or on windows: C:\Users\%USERNAME%\Documents\houdini16.0, on MAC OSX it would be: ~/Library/Preferences/houdini/16.0.

Import the module PyTake2 in your python script.

Code Example

Here is a quick example on how to use the module PyTake2. To have more information about the API, have a look on the API Documentation section bellow.

import PyTake2

geo1 = hou.node("/obj/geo1")
geo2 = hou.node("/obj/geo2")
geo3 = hou.node("/obj/geo3")
null = hou.node("/obj/geo4/null1")

print("create take1, empty")
take1 = PyTake2.Take(name="take1")

print("go back to main")
PyTake2.returnToMainTake()

print("create takeA and B")
# create take A and include all parameters from geo3 node
takeA = PyTake2.Take(name="take_A")
takeA.includeDisplayFlag(geo1)
print takeA

# create take B ( empty ) set take A as parent
takeB = PyTake2.Take(name="take_B", parent=takeA)
print("TakeB parent: " + takeB.getParent().getName())

# add parameter to take B, here we add a parm tuple ( t )
# as wel a a float parameter ( scale )
takeB.includeParms([hou.node("/obj/geo1").parmTuple("t"),
                    hou.node("/obj/geo1").parm("scale")])

# merge take C and take B
print("create takeC from take A")
takeC = PyTake2.Take(name="take_C")
takeC.includeParmsFromTake(takeA)
print("TakeC parent: " + takeC.getParent().getName())
print("TakeC members: " + str(takeC.getTakeMembers()))
print("Remove display flag from take C")
takeC.includeDisplayFlag(geo1, False)
print("TakeC members: " + str(takeC.getTakeMembers()))
PyTake2.setTake(takeC)

# create take D and set parent take A
takeD = PyTake2.Take(name="take_D")
takeD.setParent(takeA)
print("TakeD parent: " + takeD.getParent().getName())

# create take E and add parameters from a node according to a pattern
PyTake2.returnToMainTake()
takeE = PyTake2.Take(name="take_E")
takeE.includeParmsFromNode(null, ["parm*", "cacheInput"])

# set parent to None ( Main )
takeE.setParent(None)

# copy take A
takeA.copy("take_A_COPY")

print("current take:")
print PyTake2.currentTake()

 

API Documentation
PyTake2.currentTake()
Return the current take as PyTake2.Take object or None is current take is main take.
PyTake2.ls(name_only=False, pattern="", pattern_ignore_case=False)
Return the list of takes in the scene.
Return a list of Take object or a list of string if name_only is set to True.
A Houdini-style pattern can be set with pattern.
PyTake2.setAutoMode(toggle)
Set the take mode "automode" on / off.
PyTake2.setTake(take)
Set the given take as current take.
Take argument can be either a Take name ( string ) or a Take object.
PyTake2.returnToMainTake()
Set Main take as current take.
PyTake2.takeFromName()
Return a Take object from a given take name.
takeFromFile(file_path, parent="")
Create a take from a file saved with Take.saveToFile().
file_path: (str) File to load.
parent: (str) Name of parent take, if empty, parent take will be current take.
Returns a Take object.
PyTake2.TakeMember()
Used internally by Take objects to store take's members ( nodes and parameters ).
__slots__ = ["flags", "parms", "node"]
flags is a list of strings with all the flag included in the take ( display_flag, render_flag or bypass_flag)
parms is a list of hou.Parm or hou.ParmTuple objects.
node is hou.Node object.
PyTake2.Take(name="pytake", parent="", set_to_current=False, include_node=None, include_parm=None, _add_to_scene=True)
The Take class, to create a new take instanciate this class.
name: (str) Name of the take.
parent: (Take) Parent take, if empty, parent take will be current take.
set_to_current: (bool) If set to True, the take will be set as current take.
include_node: (hou.Node or string) A hou.Node object or a node path to be included in the take. It can be a list of hou.Node or string.
include_parm: (hou.parm or hou.parmTuple) a parm ( or parm tuple ) object to be included in the take. It can be a list.
_add_to_scene: (bool) Must be set to True used only internally.
take = PyTake2.Take("my_take", include_node=hou.node("/obj/geo1"),
                               include_parm=hou.parm("/obj/geo1/scale"))
PyTake2.Take.includeRenderFlag(self, node, include=True, set_flag_False, flag_value=True)
Include render flag of the node_path in the take.
node: (str) path of the node or instance of hou.Node().
include: (bool) Flag Include / Exclude switch.
set_flag: (bool) Set the node's render flag.
flag_value: (bool) Value of the flag to be set.

Raise a InvalidFlagType if the given node doesn't have a render flag.

PyTake2.Take.includeDisplayFlag(self, node, include=True, set_flag_False, flag_value=True)
Include display flag of the node_path in the take.
node: (str) path of the node or instance of hou.Node()
include: (bool) Flag Include / Exclude switch.
set_flag: (bool) Set the node's display flag.
flag_value: (bool) Value of the flag to be set.Raise a InvalidFlagType if the given node doesn't have a display flag.
PyTake2.Take.includeBypassFlag(self, node, include=True, set_flag_False, flag_value=True)
Include bypass flag of the node_path in the take.
node: (str) path of the node or instance of hou.Node()
include: (bool) Flag Include / Exclude switch.
set_flag: (bool) Set the node's bypass flag.
flag_value: (bool) Value of the flag to be set.

Raise a InvalidFlagType if the given node doesn't have a bypass flag.

PyTake2.Take.includeParms(self, parms, include=True)
Include given hou.Parm or hou.ParmTuple object(s) in the take.
take = PyTake2("mytake")
take.includeParms([hou.node("/obj/geo1").parmTuple("t"),
                    hou.node("/obj/geo1").parm("scale")])
PyTake2.Take.includeParmsFromNode(self, node, parms_name_filter=None, include=True)
Include parameters from a given hou.Node or node path object.
Parameters can be filtered with an houdini-style pattern matching "parms_name_filter"
which can be either a single string or a list of string.
null = hou.node("/obj/geo1/null")
take = PyTake2.Take(name="mytake")
take .includeParmsFromNode(null, ["parm*", "cacheInput"])
PyTake2.Take.includeParmsFromTake(self, take, force=False)
Include all parms from a given take to this take.
The take parameter can be either a Take object or a take name.
force: (bool) Force a source take has the same included parameter as the destination, the source will overwrite the destination
PyTake2.Take.getTakeMembers(self)
Returns a dictionnary of TakeMembers objects included in the take.
PyTake2.Take.getTakeMembersStr(self)
Returns a string version of take's members.
PyTake2.Take.isCurrent(self)
Returns True if the take is the current take, False otherwise.
PyTake2.Take.setCurrent(self)
Set take as current take.
PyTake2.Take.setName(self, name)
Rename the current take.
PyTake2.Take.setParent(self, parent)
Set the current take's parent, it can be either a Take object, a take name
or None.
If None, the take's parent will be set to Main take.
PyTake2.Take.getName(self)
Return take's name.
PyTake2.Take.getParent(self)
Return the take's parent as Take object, or None.
PyTake2.Take.copy(self, name="", set_current=False)
Return a copy of that take and add it to the list of take.
The copy can be set to current take with argument set_current.
PyTake2.Take.remove(self)
Remove the take from the take list.
recursive: (bool) if True, remove all child takes as well.
PyTake2.Take.existInScene(self)
Return True if take exists in the scene, False if not.
PyTake2.Take.saveToFile(self, file_path, recursive=False)
Save the given take to a external file.
file_path: (str) A valid path where to save the file.
recursive: (bool) if True, save as well as children take of the node.
Error classes
TakeError(Exception)
PyTake2.TakeCreationError(TakeError)
PyTake2.TakeDeleteError(TakeError)
PyTake2.TakeSetError(TakeError)
PyTake2.InvalidFlagType(TakeError)
PyTake2.InvalidNode(TakeError)
Changelog

v1.0.0: First commit