Python way to change hda current definition

   8763   8   3
User Avatar
Member
52 posts
Joined: June 2012
Offline
Hi,

I found my way to copy a new definition of some selected asset but I can't find how I can set the current definition before allowing editing of contents automatically.

Basically I'm looking for the function called when display all definitions menu and we change the Asset Name and Path ordered menu parameter, for example from myOtl::0.6 to myOtl::0.7

Hope I'm clear

Thanks !
Chris
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
have a look here:
http://www.sidefx.com/docs/houdini15.0/hom/hou/HDADefinition#setIsPreferred [sidefx.com]
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
52 posts
Joined: June 2012
Offline
Thanks Michael,

unfortunately that doesn't do exactly what I want. This function the equivalent of right click / use this definition in the operator manager but it doesn't change the current definition of my asset.

To be more precise I want to make a button which will easily duplicate a definition under a new version (major or minor), change the current definition and then allow editing of contents.

If you select a custom otl for which definitions are named ‘myAsset::1.4’ and paste the code below in some python script editor, once you run it it will create a new definition and set it to preferred but as you can see, doesn't make it current.


import hou

node = hou.selectedNodes()
definition = node.type().definition()
hdaFile = definition.libraryFilePath()

versions =
for d in hou.hda.definitionsInFile(hdaFile) :
versions.append(d.nodeTypeName().split('::')) #I name the definition myAsset::1.4

versions = sorted(versions)
latestMajorVersion = int(versions.split('.')) # from myAsset::1.4 -> 1
latestMinorVersion = int(versions.split('.')) # from myAsset::1.4 -> 4

print ‘hda path : %s’ % hdaFile
print ‘versions : %s’ % versions
print ‘latest major version : %s’ % versions.split('.')
print ‘latest minor version : %s’ % versions.split('.')

print ‘current definition : %s’ % definition

### Need to be careful if user is not currently using the latest definition and do some test about it

hdaNameNewVersion = ‘%s::%s.%s’ % ( definition.nodeTypeName().split('::'), latestMajorVersion, latestMinorVersion+1 )
newDefinition = definition.copyToHDAFile(hdaFile, new_name=hdaNameNewVersion) #return None no matter what but set for readability

latestDefinition = hou.hda.definitionsInFile(hdaFile)
latestDefinition.setIsPreferred(True)

Or did I miss something ?

Thanks !
Chris
User Avatar
Member
8582 posts
Joined: July 2007
Offline
http://www.sidefx.com/docs/houdini15.0/hom/hou/Node#changeNodeType [sidefx.com]

so it would be like:
node.changeNodeType(hdaNameNewVersion, keep_network_contents=False)

EDIT: also be careful about the type names in your script, as some types don' t have version number and some have more namespaces, so assuming there is a version and no namespace can be dangerous
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
52 posts
Joined: June 2012
Offline
Oh thanks Tomas ! Yes that's exactly what I wanted, I've seen this function but didn't think I could use it this way.

Thanks for your advice, this is meant to be used from the vary first time we create an asset so they should all have namespace and version formatted this way. Also this is a first rough version, I will make it smarter later on.

Thank you very much guys !
Chris
User Avatar
Member
52 posts
Joined: June 2012
Offline
Hi again,

so now that this is working, I just wanted to allow editing of contents which works fine and set the version but the setVersion function makes my Houdini crash almost everytimes I ran the script. Am I doing something illegal or there might be a bug ?

Even though it crashes, it does create a new definition and set the version properly.

Using Houdini 15.0.244.16.


################### Increase minor version and allow editing :

import hou

node = hou.selectedNodes() #grab the first selected node
definition = node.type().definition()
hdaFile = definition.libraryFilePath() #find the hda file path

versions =
for d in hou.hda.definitionsInFile(hdaFile) :
versions.append(d.nodeTypeName().split('::')) #I name the definition myAsset::1.4

latestMajorVersion = int(versions.split('.')) # from myAsset::1.4 -> 1
latestMinorVersion = int(versions.split('.')) # from myAsset::1.4 -> 4

hdaNewVersion = ‘%s.%s’ % ( latestMajorVersion, latestMinorVersion+1 )
hdaNewName = ‘%s::%s’ % ( definition.nodeTypeName().split('::'), hdaNewVersion )
newDefinition = definition.copyToHDAFile(hdaFile, new_name=hdaNewName ) #return None no matter what but set for readability

latestDefinition = hou.hda.definitionsInFile(hdaFile)
node = node.changeNodeType(hdaNewName , keep_network_contents=False)

node.allowEditingOfContents()
latestDefinition.setVersion( hdaNewVersion )


Thanks for reading me anyway !
Chris
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
this reminds me of an old bug…
please submit a simple scene/hda with a crash log in a bug report so we can have a look at this.
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
52 posts
Joined: June 2012
Offline
Thanks Michael, submitted few hours ago
User Avatar
Member
52 posts
Joined: June 2012
Offline
In case anybody may meet the same issue, so far this was actually fixed my updating Nvidia graphic drivers to the latest
  • Quick Links