delete channels with python (HOM)

   17530   7   0
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
How can I use python to delete channels? I looked through the documentation but didn't find a command. Thanks!

(Reason: I want to make a script that will loop through all the parameters of a node and delete all the channels. I know how to do the looping part now, but I don't know the command to delete the channels )
User Avatar
Member
1906 posts
Joined: Nov. 2006
Online
hou.Parm.deleteAllKeyframes() will destroy the channel/expression on a parameter. Alternatively there is also hou.ParmTuple.deleteAllKeyframes() which can delete all the channels on a parm tuple object.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
Awesome!
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
I'm a little confused about the usage… create a default box and write an expression sin($FF) in tx…

I ran this from the python shell:


>>>hou.parm.deleteAllKeyframes('/obj/box_object1/tx')

or this:
>>>hou.parm.deleteAllKeyframes(hou.node('/obj/box_object1/tx'))

and got this:

Traceback (most recent call last):
File “<console>”, line 1, in <module>
AttributeError: ‘function’ object has no attribute ‘deleteAllKeyframes’
User Avatar
Member
1906 posts
Joined: Nov. 2006
Online
hou.parm('/obj/geo1/tx').deleteAllKeyframes()

or

hou.node('/obj/geo1').parm('tx').deleteAllKeyframes()


So to delete all the channels on the object it would be:

for parm in hou.node('/obj/geo1').parms():
parm.deleteAllKeyframes()
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
got it now, thanks!
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
In appreciation of the help, here are three functions for any others that are starting python, that can be added to hou.session.module. I just started using python (not being a programmer or scripter before) and it took me a couple of days to figure it out…

It would be nice if there was a place that users could easily contribute things like this for houdini (like scriptspot.com etc)…. oh maybe the exchange.. but there's no python section yet.

———————

copyVals: copies values from one node's parameters to another.
copyParms: channel references one node with another identical node.
delParms: deletes all channels of a node.


def copyVals(sourcebox, targetbox):
mytargettuple =
for row in mytargettuple:
targetbox.parm(row).set(sourcebox.parm(row).eval())

def copyParms(sourcebox, targetbox):
mytargettuple =
for row in mytargettuple:
targetbox.parm(row).set(sourcebox.parm(row))

def delParms(targetbox):
for theparm in targetbox.parms():
theparm.deleteAllKeyframes()
User Avatar
Member
11 posts
Joined: July 2017
Offline
import toolutils

def clearAnimation(nodes):
“”“
clear all animation
”“”
for node in nodes:
if not isinstance(node, hou.NetworkBox):
for parm in node.parms():
parm.deleteAllKeyframes()

nodes = hou.selectedItems()
clearAnimation(nodes)


##paste this to a new shelf tool, it delete all selected nodes channels.
  • Quick Links