“`import hou
def lock_hda(node_path): “”” Lock the HDA at the given node path. And then Unlock it now that it has been matched “”” # Get the node node = hou.node(node_path)
# Check if node exists if node is None: print(“Node does not exist.”) return
# Lock the HDA node.matchCurrentDefinition() # Unlock the HDA node.allowEditingOfContents()
# Example usage def otherDefinitions(node_path): ”’Given an HDADefinition object, return the other loaded definitions for the same node type.”’ # Look through all the loaded hda files for definitions providing # the same node type. node = hou.node(node_path) definition = node.type().definition() node_version = definition.nodeTypeName().split(‘::’)[0] result = [] result.append(definition) for hda_file in hou.hda.loadedFiles(): # Skip the hda file containing the definition that was passed in. if hda_file == definition.libraryFilePath(): continue for other_definition in hou.hda.definitionsInFile(hda_file): # print(other_definition) if node_version in other_definition.nodeTypeName().split(‘::’)[0]: result.append(other_definition) else: pass return result def getHighestVersion(node): node_path = node.path() otherDef = otherDefinitions(node_path) highest_version_def = sorted(otherDef, key=lambda x: x.nodeTypeName().split(“::”)[1])[-1] highest_version_name = highest_version_def.nodeTypeName() node.changeNodeType(highest_version_def.nodeTypeName(), keep_parms=True) print(f”Updated HDA {node_path} to version {highest_version_name}”) nodeM = hou.node(‘/path/to/your_node’) # replace path with actual node path node_path = nodeM.path() # get the node path since after we replace the type the direct reference will no longer exist
getHighestVersion(nodeM) # update the HDAs version type
lock_hda(node_path) # lock and unlock the HDA to match internal contents “`
justt got this guy done thought id share since i had to do some digging on how to do it! takes an input node and gets the highest version of that HDA and then updates it to that version and locks and unlocks the HDA to match contents!