nodeutils module

class nodeutils.Glob(pattern, pos, capturing=True)

Bases: nodeutils.Part

as_regex()
is_glob = True
is_star()
replacement(context)
class nodeutils.GroupRef(text, num)

Bases: nodeutils.Part

as_regex()
replacement(context)
class nodeutils.Literal(text)

Bases: nodeutils.Part

as_regex()
replacement(context)
class nodeutils.Negation(pattern)

Bases: nodeutils.Part

as_regex()
is_negation()
replacement(context)
exception nodeutils.NodeMissingError

Bases: exceptions.Exception

class nodeutils.Part

Bases: object

as_regex()
is_glob = False
is_negation()
is_star()
replacement(context)
class nodeutils.RenameContext(find_parts)
nodeutils.check_conflicts(network, find, replace, selected=False, whole_name=False, unique_names=False)
nodeutils.count_conflicts(changes)
nodeutils.find_and_replace(find, replace, names, whole_name=False, ignore_case=True)

Returns a list of (oldname, newname) changes to make given the find string, replace string, and list of names to consider. The list of names can be from all nodes in the current network or the selected nodes.

Parameters:
  • find – a string containing the text/globs to search for.
  • replace – a string containg the text/globs to replace matches with.
  • names – the list of names to consider for renaming.
  • whole_name – whether the “find” pattern must match the entire name. If this is False, substring matches are allowed.
  • ignore_case – whether to ignore uppercase/lowercase differences when comparing names.
Returns:

list of (oldname, newname) tuples.

nodeutils.find_conflicts(network, changes, unique_names=False)

Generates a list of (oldname, newname, error) tuples. This can be used to present a preview to the user with any potential conflicts noted.

Parameters:
  • network – a hou.Node object representing the network in which the renames will take place.
  • changes – a list of (oldname, newname) tuples.
  • unique_names – If True, renames that conflict with existing names will have numbers appended. This means this function will not report existing name conflicts as errors.
Returns:

a generator of (oldname, newname, message) tuples, where message is an error message string or None.

nodeutils.find_renames(network, find, replace, selected=False, whole_name=False, unique_names=False, ignore_case=True)

For use by the GUI, finds renames for the given network, and returns a list of (oldname, newname, error) tuples. This does not rename anything; it just returns the information to populate the GUI.

Parameters:
  • network – a hou.Node object representing the parent network.
  • find – the string/globs to find.
  • replace – the string/globs to replace matches with.
  • selected – whether to try to rename all nodes (selected=False) or only the currently selected nodes (selected=True).
  • whole_name – whether the “find” pattern must match the entire name. If this is False, substring matches are allowed.
  • unique_names – If True, renames that conflict with existing names will have numbers appended.
  • ignore_case – whether to ignore uppercase/lowercase differences when comparing names.
Returns:

list of (oldname, newname, error) tuples.

nodeutils.find_renames_list(matching_networks, find, replace, selected=False, whole_name=False, unique_names=False, enable_pattern=False, ignore_case=True)

Returns find_renames changes for a list of networks. If pattern_matching is enabled, oldname and newname are replaced by the full path of the old node name and new node name instead.

nodeutils.rename_nodes(network, find, replace, selected=False, whole_name=False, errors=None, unique_names=False, fail_fast=False, ignore_case=True)

A high-level function to rename nodes, for use in scripts. Unlike the GUI equivalent, this function does not check the validity of the renames first.

This function will perform the renames it can, and ignore renames that cause an error (such as renaming to an invalid name or renaming to a name that exists). If you supply a list in the errors argument, the function will append tuples to it representing the renames that failed.

The function returns True if all renames were successful, or False if there were any errors.

The function puts the renames inside an undo block, you can undo any renames performed by calling hou.undos.performUndo().

Parameters:
  • network – a hou.Node object representing the parent network.
  • find – the string/globs to find.
  • replace – the string/globs to replace matches with.
  • selected – whether to try to rename all nodes (selected=False) or only the currently selected nodes (selected=True).
  • whole_name – whether the “find” pattern must match the entire name. If this is False, substring matches are allowed.
  • errors – if this is not None, the function assumes it’s a list and appends (oldname, newname, error_msg) tuples to it each time a rename fails.
  • unique_names – If True, renames that conflict with existing names will have numbers appended.
  • fail_fast – if True, the function exits after the first error, instead of ignoring errors and trying to perform the other renames.
  • ignore_case – whether to ignore uppercase/lowercase differences when comparing names.
nodeutils.rename_nodes_list(matching_networks, find, replace, selected=False, whole_name=False, errors=None, unique_names=False, fail_fast=False, ignore_case=True)

Rename nodes for a list of networks.