Hello,
I am working on a digital asset publishing system which is quite similar to this thread [sidefx.com].
However, I have a bit of a different problem now. I'd like to be able to roll back changes made, as in, go back a version on my asset. So far I've successfully gotten my asset to downgrade itself to an older version, but I'm having an issue where – after I set the old version as preferred, changeNodeType(previous_version) and uninstall the unwanted version – my asset doesn't change the current definition to the previous version. Instead it just lists the current version as blank, and I have to manually change the working definition with the dropdown menu.
The HDADefinition class has a method for “isCurrent()”, but not one for “setIsCurrent()”, even though there is one for “setIsPreferred”. How can I set the current HDA Definition with Python?
Thanks,
Chris
Python: Set Current HDA Definition
5901 12 2- VFXLife
- Member
- 16 posts
- Joined: March 2016
- Offline
- el_diablo
- Member
- 133 posts
- Joined: July 2005
- Offline
I haven't tried but if you set preferred and then force sync, maybe you'll get the version right. Also https://www.sidefx.com/docs/houdini/hom/hou/Node [sidefx.com] , syncNodeVersionIfNeeded(version) might do the trick.
Edited by el_diablo - Nov. 30, 2016 05:57:46
- VFXLife
- Member
- 16 posts
- Joined: March 2016
- Offline
el_diablo
I haven't tried but if you set preferred and then force sync, maybe you'll get the version right. Also https://www.sidefx.com/docs/houdini/hom/hou/Node [sidefx.com] , syncNodeVersionIfNeeded(version) might do the trick.
Thanks, that was a good idea. I've been working the code a bit more and now I'm stuck in a same-but-different scenario. Now what happens is this:
> Start with myAsset::1.02, also has versions 1.00 and 1.01 in operator type library
> Run my script to downgrade to myAsset::1.01
- changeNodeType to myAsset::1.01
- set 1.01 as preferred
- uninstall 1.02
- matchCurrentDefinition, syncNodeVersionIfNeeded
> node becomes myAsset::1.00
Instead of being a blank option, now the Asset Name dropdown is set to 1.00 instead of 1.01, even though I'm making sure to have 1.01 set as preferred and 1.01 is the latest definition on disk etc.
What am I doing wrong?
Here's the relevant parts of the script (variable names changed to make it obvious):
def revertHDA(): node = hou.selectedNodes()[-1] v1.02_definition = node.type().definition() v1.01_definition = hou.hda.definitionsInFile(old_hda)[-1] v1.01_definition_name = v1.01_definition.nodeTypeName() reverted_node = node.changeNodeType(new_node_type=v1.01_definition_name, keep_network_contents=False, force_change_on_node_type_match=True) v1.01_definition.setIsPreferred(True) hou.hda.uninstallFile(v1.02) if reverted_node.isLockedHDA(): reverted_node.allowEditingOfContents() reverted_node.matchCurrentDefinition() reverted_node.syncNodeVersionIfNeeded(v1.02) os.remove(v1.02_hda)
- VFXLife
- Member
- 16 posts
- Joined: March 2016
- Offline
Okay in case anyone else runs into this issue in the future:
The problem here was that I was uninstalling and deleting the unwanted hda file after setting the new version. I don't know why that caused Houdini to react this way (setting the current asset's version down 1) but I did quite a bit of testing and that was it. So essentially, just make sure you uninstallFile(unwanted_hda) and os.remove(unwanted_hda) BEFORE you matchCurrentDefinition and sync, etc.
Happy Pythoning!
The problem here was that I was uninstalling and deleting the unwanted hda file after setting the new version. I don't know why that caused Houdini to react this way (setting the current asset's version down 1) but I did quite a bit of testing and that was it. So essentially, just make sure you uninstallFile(unwanted_hda) and os.remove(unwanted_hda) BEFORE you matchCurrentDefinition and sync, etc.
Happy Pythoning!
- kahuna031
- Member
- 897 posts
- Joined: July 2018
- Offline
This was quite a painful experience. I tried to copy the hda from our shared dir to the prefs dir but couldn't get Houdini to use the definition from the new file. Ended up to deleting the old file which sorted it but would appreciate a more direct workflow. Iaw, an equivalent python function to switching path in the definition dropdown menu (see attachment).
B.Henriksson, DICE
- jsmack
- Member
- 7803 posts
- Joined: Sept. 2011
- Offline
kahuna031
This was quite a painful experience. I tried to copy the hda from our shared dir to the prefs dir but couldn't get Houdini to use the definition from the new file. Ended up to deleting the old file which sorted it but would appreciate a more direct workflow. Iaw, an equivalent python function to switching path in the definition dropdown menu (see attachment).
hou.hda.installFile is what you want to use. or the hou.hda.reloadFile if it was already installed. Newer files are always preferred automatically. If you copied the file, then it will be newer and thus preferred. If you want to force it to be used, there is force flag on installFile. There is also hou.HDADefinition.setIsPreferred() to explicitly force a definition to be preferred. To force all definitions in an HDA file to preferred, you will need to loop over hou.hda.definitionsInFile(), calling setIsPreferred on each.
- kahuna031
- Member
- 897 posts
- Joined: July 2018
- Offline
- jsmack
- Member
- 7803 posts
- Joined: Sept. 2011
- Offline
- kahuna031
- Member
- 897 posts
- Joined: July 2018
- Offline
After these commands I expect the hda in my document folder to be used in the Asset Manager (even if I refresh). It seems to me the setIsPreferred is a soft command, is there any reasoning to why we can't have a forced function like the said path drop down menu in the parameter tab or “Use this definition” in the Asset Manager's RMB menu?
B.Henriksson, DICE
- jsmack
- Member
- 7803 posts
- Joined: Sept. 2011
- Offline
- kahuna031
- Member
- 897 posts
- Joined: July 2018
- Offline
- jsmack
- Member
- 7803 posts
- Joined: Sept. 2011
- Offline
- kahuna031
- Member
- 897 posts
- Joined: July 2018
- Offline
-
- Quick Links