Set the default values for an HDA via Python

   5744   8   1
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
When saving an HDA via python, how can I set the default values for said HDA? I'm able to copy the parameters via the following code, but would love to set their initial values as defaults as well.

params = node.parmTemplateGroup()
ogParms = node.parms()

# create a digital asset from the given node
hdaNode = node.createDigitalAsset(
	name=name,
	hda_file_name=filepath,
	max_num_inputs=1,
	version=str(version),
	ignore_external_references=True,
	create_backup=False)

# restore the nodes params
hdaNode.type().definition().setParmTemplateGroup(params)

# save the digital asset again
# after restoring it's params
hdaNode.type().definition().updateFromNode(hdaNode)
hdaNode.matchCurrentDefinition()
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Staff
3456 posts
Joined: July 2005
Offline
you'll have to use hscirpt right now - there is an RFE to have a HOM version of “Copy Defaults From Nodes”

otwrite -i -o -l

see http://www.sidefx.com/docs/houdini/commands/otwrite.html [www.sidefx.com]
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
Awesome, that totally works. Here's the resulting command:

command = 'otwrite -d -i -l -o %s %s' % (node.path(), filepath)
result = hou.hscript(command)

FWIW I actually ended up bypassing Houdini's HDA system all together and just using saveItemsToFile(). I can then call loadItemsFromFile() to get the nodes back and manage the versioning etc myself.
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
Is there by chance an hscript command to set the default of a given parameter?

I looked through http://www.sidefx.com/docs/houdini/commands/opparm.html [www.sidefx.com] and couldn't find anything there, same on the python side of things.
Edited by blented - Jan. 15, 2019 10:30:50
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Staff
3456 posts
Joined: July 2005
Offline
look for ‘setDefaultValue’ in the parmTempates
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
Lovely! It doesn't show up under hou.ParmTemplate which makes sense now as not everything has a setDefaultValue.

http://www.sidefx.com/docs/houdini/hom/hou/FloatParmTemplate.html [www.sidefx.com]

Thanks a bunch for the tips
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Member
86 posts
Joined: Jan. 2009
Offline
Just in case someone else stumbles across this…or I stumble back across it in the future when I need to do this again. Here's some code that will set the default value of a parameter on a node:
node_path = '/obj/subnet1'
parm_name = 'parm'
newDefaultValue = 2.0
#get node
n=hou.node(node_path)
#get parmTemplateGroup
ptg=n.parmTemplateGroup()
#get copy of parm in parmTemplateGroup
p = ptg.find(parm_name)
#set new default value on our copy
p.setDefaultValue((newDefaultValue,))
#replace parm in parmTemplateGroup with our copy
ptg.replace(ptg.find(parm_name),p)
#apply parmTemplateGroup to node
n.setParmTemplateGroup(ptg)
Please note that this only sets it on the instance of the node in your scene, not on the HDA itself.
User Avatar
Member
260 posts
Joined: Nov. 2014
Offline
Thank you very much for provided info.
Would you know how to change default value for the OTL and not just the scene instance?
User Avatar
Member
7863 posts
Joined: Sept. 2011
Offline
martinkindl83
Thank you very much for provided info.
Would you know how to change default value for the OTL and not just the scene instance?

instead of setting the node's parmTemplateGroup, set the nodetype's definition's ptg.

node_path = '/obj/subnet1'
parm_name = 'parm'
newDefaultValue = 2.0
#get node
n=hou.node(node_path)
# get definition
ndef = n.type().definition()
#get parmTemplateGroup
ptg=ndef.parmTemplateGroup()
#get copy of parm in parmTemplateGroup
p = ptg.find(parm_name)
#set new default value on our copy
p.setDefaultValue((newDefaultValue,))
#replace parm in parmTemplateGroup with our copy
ptg.replace(ptg.find(parm_name),p)
#apply parmTemplateGroup to node
ndef.setParmTemplateGroup(ptg)
  • Quick Links