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
Python way to change hda current definition
9289 8 3- chistof
- Member
- 52 posts
- Joined: 6月 2012
- Offline
- goldfarb
- スタッフ
- 3459 posts
- Joined: 7月 2005
- Offline
- chistof
- Member
- 52 posts
- Joined: 6月 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
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
- tamte
- Member
- 8730 posts
- Joined: 7月 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
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
FX Supervisor
Method Studios, NY
- chistof
- Member
- 52 posts
- Joined: 6月 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
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
- chistof
- Member
- 52 posts
- Joined: 6月 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
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
- goldfarb
- スタッフ
- 3459 posts
- Joined: 7月 2005
- Offline
- chistof
- Member
- 52 posts
- Joined: 6月 2012
- Offline
- chistof
- Member
- 52 posts
- Joined: 6月 2012
- Offline
-
- Quick Links