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
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.
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
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
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.
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