python: change node type

   725   3   1
User Avatar
Member
55 posts
Joined: 3月 2016
Offline
Hi

I need to change the node type in several nodes, I am taking about an HDA, I have to replace them by another simuilar one, same parameters, but different content.

I can´t find a method to do it in the hou.Node documentation.
there is a method to swap the node type? .. or change the version of an HDA.

Thanks
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
87 posts
Joined: 5月 2011
Offline
https://www.sidefx.com/docs/houdini/hom/hou/OpNode.html [www.sidefx.com]

Look at the changeNodeType() Method...
— dedeks 3000 —
User Avatar
Member
10 posts
Joined: 2月 2017
Offline
Here is a possible solution.
Keep in mind that this is a naive approach since an hda file can contain multiple definitions.

I would be interested to know if someone has a better way.

import hou


def replace_type_instances(src_type, dst_type):
    for instance in src_type.instances():
        if instance.isEditableInsideLockedHDA():
            keep_network_contents = not instance.matchesCurrentDefinition()
            new_node = instance.changeNodeType(
                dst_type.name(),
                keep_parms=True,
                keep_network_contents=keep_network_contents
            )


def get_hda_first_type(hda_filepath):
    definitions = hou.hda.definitionsInFile(hda_filepath)
    for definition in definitions:
        return definition.nodeType()


def main():
    src_type = get_hda_first_type('/path/to/src.hda')
    dst_type = get_hda_first_type('/path/to/dst.hda')
    if src_type and dst_type:
        dst_type.definition().setIsPreferred(True)
        with hou.undos.group('Replace type instances'):
            replace_type_instances(src_type, dst_type)


main()
User Avatar
Member
55 posts
Joined: 3月 2016
Offline
thanks!... I will try it
Gerardo Castellanos
www.gerardocastellanos.com
  • Quick Links