How to create an OTL/HDA in a python script

   11673   14   3
User Avatar
Member
790 posts
Joined: April 2020
Offline
Hello all,

I am generating some nodes in a subnet from within a python script. In the hou.hda and related modules I have found several functions to install and edit hda's.

However, I was unable to find the command that is the equivalent of the “create digital asset” right mouse button option. What would be the proper way to convert a subnet into a digital asset in python?

Thanks.

Koen
User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
Take a look at hou.Node.createDigitalAsset. It will do what you need.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
790 posts
Joined: April 2020
Offline
Perfect, thanks!

Koen
User Avatar
Member
790 posts
Joined: April 2020
Offline
Hello Graham,

Hopefully another easy one,

I am looking for the function to set the value that can be retrieved through the hou.HDADefinition.hideDefaultParameters() function.

Can you point me to this?

Thanks,

Koen
User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
Unfortunately there are some issues with that now because of the fact that that toggle was removed from the Type Properties dialog early in 9.1 development and the ability is somewhat unreliable now since the visibility is now controlled on a per parameter basis. The way to actually do it is to modify the extra info of the asset definition by telling it to hidedefaultparms.

info = hou.HDADefinition.extraInfo()
hou.HDADefintion.setExtraInfo(info + “hidedefaultparms”)


There are a few problems with this now though because it has problems hiding folders and if you were to run it on a newly created digital asset from a geo object it would leave all the folders and non-default rendering parameters.

Overall it's possible but it may not give you exactly what you are wanting.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
790 posts
Joined: April 2020
Offline
Thanks Graham,

I'll give it a try. I am trying to build hda's on the fly to import stuff. They are based on a geometry object. Since we wont be using a lot of the default parameters, it seemed cleaner to hide them. It is purely cosmetic though.

Is is possible to change the order of the folders? If I could add a folder as the first one, and make that the default visible folder, it might be almost as clean.

Cheers,
Koen
User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
Unfortunately ways to manipulate existing parameters or add new ones, especially folders aren't really available still so it would be very problematic, if not impossible to try and do something like that.

What I would do, and did with the Autorig stuff is that I created a default Geo asset, removed all the spare parms I didn't need/want, hide the 4 default folders through the Type Properties menu so I had my simple blank slate with all the stuff hidden, then saved out the dialog script so when I want to create an asset on the fly I just read in my geo.ds file, and set the contents of the DialogScript section to be that and it happily assumes my default slate. This is nice because you can customize your parameter set more, hide what you want and then set it to the asset.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
790 posts
Joined: April 2020
Offline
I'll look into that,

thanks again :-)
User Avatar
Member
790 posts
Joined: April 2020
Offline
Hello Graham,

All has been going pretty smooth so far. I am creating an otl from a python script. I have been adding the parameters as spare parameters on the subnet before calling node.createDigitalAsset() This way I get all the parameters on the HDA in an easy way.

for example
# add parameter to the node to switch this part off:
template = hou.ToggleParmTemplate(name = node.name(), label = node.name(), default_value = True)

param = geoNode.addSpareParmTuple(template,(“Parameters”,),True)

# link the switch node setting to the parameter on the node
subNode.parm(“enable”).setExpression('ch(“../%s”)' % node.name())

This has been working fine.

However, currently I would like to have the “render” button from a geometry rop inside the otl to show up on the dynamically generated otl.

Is there an easy way to create a link between two parameters in python?

Thanks,
Koen
User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
You can simply set a parameter to be another parameter by setting it with another hou.Parm object and it will generate your reference for you.

In the case of the render button, you just have to create your button, in this case I called it “execute” since that is it's name on the output driver then tell the button on the output driver to reference the button on the asset.

subNode.parm(“execute”).set(geoNode.parm(“execute”))

You can use this for all parameters so instead of doing
subNode.parm(“enable”).setExpression('ch(“../%s”)' % node.name())
you just need to do
subNode.parm(“enable”).set(geoNode.parm(node.name())
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
790 posts
Joined: April 2020
Offline
Wow,

that's easy, thanks!

Koen
User Avatar
Member
790 posts
Joined: April 2020
Offline
Hello Graham,

I have come pretty far generating otl's on the fly. I did come across one hurdle that remains unclear to me.

I need to add some parameters to an hda, it is an object level hda. My initial approach was to add spare parameters to the subnet before calling createDigitalAsset on it.

However when putting down an instance of the new type, the spare parameters are not there.

What is the preferred / correct way of adding parameters to an hda using python only?

Thanks for any help,

Koen
User Avatar
Member
1913 posts
Joined: Nov. 2006
Offline
Running a quick test I think I see what the problem is and a way to get around it.

When creating the assets through the interface, when spare parameters are on the node, there is the dialog that pops up allowing you to choose to destroy them, or keep them and if you choose to keep them they are properly converted to your standard asset parameters. However, it would seem that when doing thing using hou.Node.createDigitalAsset() there is no option to control the behavior and the parameters remain Spare parms. I think the best solution would be for the function to provide this kind of control.

I think the only solution is to take advantage of the option to Save Spare Parameters on the Basic tab in the Operator Type Properties. This will basically create an oncreated script that will add the spare parms to the instance of the asset. Scripting it involves using a hou.HDAOptions object. This will allow you to tell your asset definition to save those spare parms and then you update the definition from the instance of the asset you have just created and any future ones created will have the spare parms.

my_asset = hou.Node.createDigitalAsset()
my_definition = my_asset.type().definition()

my_options = hou.HDAOptions()
my_options.setSaveSpareParms(True)

my_definition.setOptions(my_options)
my_definition.updateFromNode(my_asset)


Hope that helps. I'll look at submitting an RFE for the option in hou.Node.createDigitalAsset
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
790 posts
Joined: April 2020
Offline
Jut saw your message, I was trying this and it seemed to work, from your example the save does not seem necessary, which is good.


Can I request a feature: I would love to be able to pass an options object in the createDigitalAsset call.

Thanks,
Koen


hda = geoNode.createDigitalAsset(name=geoNode.name(), hda_file_name = getHdaFile(geoNode.name()))

#make sure the spare parameters are stored in the hda as well
hdaDefinition = hda.type().definition()
hdaOptions = hdaDefinition.options()
hdaOptions.setSaveSpareParms(True)
hdaDefinition.setOptions(hdaOptions)
hdaDefinition.save(hdaDefinition.libraryFilePath(), hda, hdaOptions)
User Avatar
Member
618 posts
Joined: Aug. 2008
Offline
thats a cool trick.
  • Quick Links