Python after creating digital asset, unable to add section

   1468   2   0
User Avatar
Member
1 posts
Joined: March 2017
Offline
hda_node = subnet.createDigitalAsset(
    name=snip_name,
    hda_file_name=path,
    description=None,
    min_num_inputs=0,
    max_num_inputs=0,
    compress_contents=False,
    comment=None,
    version=None,
    save_as_embedded=False,
    ignore_external_references=False,
    change_node_type=True,
    create_backup=True,
    install_path="Scanned Asset Library Directories")
hda_node.allowEditingOfContents(propagate=True)
on_created_body = "hda_node = kwargs.get('node')"
on_created_body += "\nprint('hello', hda_node)"
hdadef = hda_node.type().definition()
# these two lines fail most of the time...
hdadef.addSection("OnCreated", on_created_body)
hdadef.setExtraFileOption("OnCreated" + "/IsPython", True)

When calling either of the lines hdadef.addSection or hdadef.setExtraFileOption, I get a popup warning
"The attempted operation failed. Failed to save updated definition."

How can I set the node definition section safely, without getting this error.

Thanks for any help
User Avatar
Member
7 posts
Joined: April 2023
Offline
Hello this is Gulshan Negi
Well, there may be some reasons for this and I search about it on the Google, and I found that there are some common issues that you may want to check:

1. Permissions: Make sure that the user running the script has write access to the node definition file.
2. Definition locked: Sometimes, the node definition file may be locked by another user or process. Try closing the node in the Houdini interface, and then running the script again.
3. Incorrect path: Double-check that the path to the node definition file is correct. If the path is incorrect, Houdini may not be able to locate the file and save the changes.

I am sure any one of them can help you.
Thanks
User Avatar
Member
12 posts
Joined: May 2015
Offline
Hey Braden. I ran your code as is (almost - just took out the install_path argument) and it ran fine and the extra section has been added to the hda. So, the code itself doesn't seem to be the problem..
  • Quick Links