def _get_tool_style(self, node_type):
        """Look for a color match based on the node type's Tab menu
        locations.

        :param node_type: Node type to style by tab menu location
        :type node_type: hou.NodeType
        :return: An applicable styling object.
        :rtype: StyleConstant|StyleRule

        """
        categories = (node_type.category().name(), constants.ALL_CATEGORY_KEY)
        # Get any Tab menu locations the node type might show up in.
        menu_locations = _get_tool_menu_locations(node_type)

        for category_name in categories:
            # Check for rules for the node type category.
            if category_name in self.tool_rules:
                # Process the locations, looking for the first match.
                for location in menu_locations:
                    # Check if the location matches any of the category rules.
                    for rule in self.tool_rules[category_name].itervalues():
                        if hou.patternMatch(rule.name, location):
                            return self._resolve_rule(rule)

        return None
Exemple #2
0
def ls(name_only=False, pattern="", pattern_ignore_case=False):
    '''
        Return the list of takes in the scene.
        Return a list of Take object or a list of string if name_only is set to True.
        A Houdini-style pattern can be set with pattern.
    '''

    if name_only:
        return _listTakeNames()

    out_list = []
    for take in _listTakeNames():
        if take == "Main":
            continue

        if pattern:

            m = hou.patternMatch(pattern, take, pattern_ignore_case)
            if m == 1:
                out_list.append(_readScript(take, make_current=False))

        else:
            out_list.append(_readScript(take, make_current=False))

    return out_list
Exemple #3
0
def ls(name_only=False, pattern="", pattern_ignore_case=False):
    '''
        Return the list of takes in the scene.
        Return a list of Take object or a list of string if name_only is set to True.
        A Houdini-style pattern can be set with pattern.
    '''

    if name_only:
        return  _listTakeNames()

    out_list = []
    for take in _listTakeNames():
        if take == "Main":
            continue
        
        if pattern:
            
            m = hou.patternMatch(pattern, take, pattern_ignore_case)
            if m == 1:
                out_list.append(_readScript(take, make_current=False))

        else:
            out_list.append(_readScript(take, make_current=False))
        
    return out_list
    def _get_node_type_style(self, node_type):
        """Look for a style match based on the node type's name.

        :param node_type: Node type to style by name
        :type node_type: hou.NodeType
        :return: An applicable styling object.
        :rtype: StyleConstant|StyleRule

        """
        type_name = node_type.nameComponents()[2]

        # Get the category name from the node and also check the 'all'
        # category.
        categories = (node_type.category().name(), constants.ALL_CATEGORY_KEY)

        for category_name in categories:
            # Check if the category has any rules.
            if category_name in self.node_type_rules:
                # Check if the node type name matches any of the category
                # rules.
                for rule in self.node_type_rules[category_name].itervalues():
                    if hou.patternMatch(rule.name, type_name):
                        return self._resolve_rule(rule)

        return None
Exemple #5
0
    def _get_node_type_style(self, node_type):
        """Look for a style match based on the node type's name.

        :param node_type: Node type to style by name
        :type node_type: hou.NodeType
        :return: An applicable styling object.
        :rtype: StyleConstant or StyleRule

        """
        type_name = node_type.nameComponents()[2]

        # Get the category name from the node and also check the 'all'
        # category.
        categories = (node_type.category().name(), constants.ALL_CATEGORY_KEY)

        for category_name in categories:
            # Check if the category has any rules.
            if category_name in self.node_type_rules:
                # Check if the node type name matches any of the category
                # rules.
                for rule in self.node_type_rules[category_name].values():
                    if hou.patternMatch(rule.name, type_name):
                        return self._resolve_rule(rule)

        return None
Exemple #6
0
    def _get_tool_style(self, node_type):
        """Look for a color match based on the node type's Tab menu
        locations.

        :param node_type: Node type to style by tab menu location
        :type node_type: hou.NodeType
        :return: An applicable styling object.
        :rtype: StyleConstant or StyleRule

        """
        categories = (node_type.category().name(), constants.ALL_CATEGORY_KEY)
        # Get any Tab menu locations the node type might show up in.
        menu_locations = _get_tool_menu_locations(node_type)

        for category_name in categories:
            # Check for rules for the node type category.
            if category_name in self.tool_rules:
                # Process the locations, looking for the first match.
                for location in menu_locations:
                    # Check if the location matches any of the category rules.
                    for rule in self.tool_rules[category_name].values():
                        if hou.patternMatch(rule.name, location):
                            return self._resolve_rule(rule)

        return None
Exemple #7
0
def readSinglePattern(node, geo, type):
    nodePath = node.path()
    function = inspect.stack()[0][3]
    try:
        filePath = node.hm().path.filePath(node)
        label_pattern = node.evalParm("label")
        prefix_pattern = node.evalParm("prefix")
        folderSubType = node.hm().path.folderSubType(node)
        data_level = node.hm().path.folderDataType(node)

        tile = "_x{}_y{}".format(
            str(node.evalParm("tilex")).zfill(2),
            str(node.evalParm("tiley")).zfill(2))

        root, f = os.path.split(filePath)

        if data_level == "tile":
            files = [n for n in os.listdir(root) if tile in n]
        else:
            files = os.listdir(root)

        for f in files:

            # check if label matches
            if label_pattern and label_pattern != '*':
                current = f.split(folderSubType + '_')[-1]

                file_pattern = current.split(tile)[0]
                if not hou.patternMatch(label_pattern, file_pattern):
                    continue

            # check if prefix matches
            if prefix_pattern and prefix_pattern != '*':
                _p = f.split(folderSubType)[0]
                if not _p:
                    continue
                if not hou.patternMatch(prefix_pattern, _p):
                    continue

            file = path_root + '/' + f
            node.hm().file.load(node, geo, file)

    except (KeyboardInterrupt, SystemExit):
        print("Interrupt requested of " + function + " for " + nodePath +
              "...exiting")
        return
    def setProperty(self):
        # Is this property being applied using a name mask.
        if self.mask is not None:
            # Get the name of the item that is currently being filtered.
            filteredItem = mantra.property(self.maskPropertyName)[0]

            # If the mask pattern doesn't match, abort.
            if not hou.patternMatch(self.mask, filteredItem):
                return

        # Call the super class function to set the property.
        super(MaskedPropertySetting, self).setProperty()
    def setProperty(self):
        # Is this property being applied using a name mask.
        if self.mask is not None:
            # Get the name of the item that is currently being filtered.
            filteredItem = mantra.property(self.maskPropertyName)[0]

            # If the mask pattern doesn't match, abort.
            if not hou.patternMatch(self.mask, filteredItem):
                return

        # Call the super class function to set the property.
        super(MaskedPropertySetting, self).setProperty()
    def _getTypeColor(self, nodeType):
        # Get the category name from the node.
        categoryName = nodeType.category().name()

        typeName = nodeType.nameComponents()[2]

        # Check if the category has any entries.
        if categoryName in self.nodes:
            # Check if the node type name matches any of the category entries.
            for colorEntry in self.nodes[categoryName]:
                if hou.patternMatch(colorEntry.name, typeName):
                    return colorEntry.color

        return None
    def _getTypeColor(self, nodeType):
        # Get the category name from the node.
        categoryName = nodeType.category().name()

        typeName = nodeType.nameComponents()[2]

        # Check if the category has any entries.
        if categoryName in self.nodes:
            # Check if the node type name matches any of the category entries.
            for colorEntry in self.nodes[categoryName]:
                if hou.patternMatch(colorEntry.name, typeName):
                    return colorEntry.color

        return None
    def _getNameEntry(self, node):
        # Get the category name from the node.
        categoryName = node.type().category().name()

        # The node name.
        name = node.name()

        # Check for entries for the node type category.
        if categoryName in self.names:
            # Check if the name matches any of the category entries.
            for colorEntry in self.names[categoryName]:
                if hou.patternMatch(colorEntry.name, name):
                    return colorEntry.color

        return None
Exemple #13
0
    def _getTypeEntry(self, nodeType, categoryName=None):
        # Get the category name from the node.
        if categoryName is None:
            categoryName = nodeType.category().name()

        typeName = nodeType.nameComponents()[2]

        # Check if the category has any entries.
        if categoryName in self.nodes:
            # Check if the node type name matches any of the category entries.
            for pattern, color in self.nodes[categoryName].iteritems():
                if hou.patternMatch(pattern, typeName):
                    return color

        return None
Exemple #14
0
    def _getTypeEntry(self, nodeType, categoryName=None):
        # Get the category name from the node.
        if categoryName is None:
            categoryName = nodeType.category().name()

        typeName = nodeType.nameComponents()[2]

        # Check if the category has any entries.
        if categoryName in self.nodes:
            # Check if the node type name matches any of the category entries.
            for pattern, color in self.nodes[categoryName].iteritems():
                if hou.patternMatch(pattern, typeName):
                    return color

        return None
    def _getNameEntry(self, node):
        # Get the category name from the node.
        categoryName = node.type().category().name()

        # The node name.
        name = node.name()

        # Check for entries for the node type category.
        if categoryName in self.names:
            # Check if the name matches any of the category entries.
            for colorEntry in self.names[categoryName]:
                if hou.patternMatch(colorEntry.name, name):
                    return colorEntry.color

        return None
Exemple #16
0
    def setProperty(self):
        """Set the property under mantra."""
        import hou

        # Is this property being applied using a name mask.
        if self.mask is not None:
            # Get the name of the item that is currently being filtered.
            filtered_item = getProperty(self.mask_property_name)

            # If the mask pattern doesn't match, abort.
            if not hou.patternMatch(self.mask, filtered_item):
                return

        # Call the super class function to set the property.
        super(MaskedPropertySetter, self).setProperty()
Exemple #17
0
    def _getNameEntry(self, node):
        """Look for a color match based on the node name."""
        # The node name.
        name = node.name()

        categories = (node.type().category().name(), "all")

        for category_name in categories:
            # Check for entries for the node type category.
            if category_name in self.names:
                # Check if the name matches any of the category entries.
                for color_entry in self.names[category_name].itervalues():
                    if hou.patternMatch(color_entry.name, name):
                        return self._resolveEntry(color_entry)

        return None
Exemple #18
0
    def _getNameEntry(self, node):
        """Look for a color match based on the node name."""
        # The node name.
        name = node.name()

        categories = (node.type().category().name(), "all")

        for category_name in categories:
            # Check for entries for the node type category.
            if category_name in self.names:
                # Check if the name matches any of the category entries.
                for color_entry in self.names[category_name].itervalues():
                    if hou.patternMatch(color_entry.name, name):
                        return self._resolveEntry(color_entry)

        return None
Exemple #19
0
    def _getNameEntry(self, node, categoryName=None):
        # Get the category name from the node.
        if categoryName is None:
            categoryName = node.type().category().name()

        # The node name.
        name = node.name()

        # Check for entries for the node type category.
        if categoryName in self.names:
            # Check if the name matches any of the category entries.
            for pattern, color in self.names[categoryName].iteritems():
                if hou.patternMatch(pattern, name):
                    return color

        return None
Exemple #20
0
    def _getNameEntry(self, node, categoryName=None):
        # Get the category name from the node.
        if categoryName is None:
            categoryName = node.type().category().name()

        # The node name.
        name = node.name()

        # Check for entries for the node type category.
        if categoryName in self.names:
            # Check if the name matches any of the category entries.
            for pattern, color in self.names[categoryName].iteritems():
                if hou.patternMatch(pattern, name):
                    return color

        return None
Exemple #21
0
    def includeParmsFromNode(self, node, parms_name_filter=None, include=True):
        '''
            Include parameters from a given hou.Node or node path object.
            Parameters can be filtered with an houdini-style pattern matching "parms_name_filter"
            which can be either a single string or a list of string.
        '''

        if not hasattr(parms_name_filter, "__iter__"):
            if parms_name_filter is None:
                parms_name_filter = []
            else:
                parms_name_filter = [parms_name_filter]

        # Check node
        node = self._convertNode(node)
        node_path = node.path()
        
        # Include flag
        if include:
            include_flag = ""
        else:
            include_flag = "-u"
        
        self.setCurrent()

        # whole node ( no filer )
        if not parms_name_filter:
            result = hou.hscript("takeinclude {0} {1} *".format(include_flag,
                                                                node_path))
            if result[1]:
                raise TakeSetError(result[1])

            for parm in node.parms():
                self._updateSavedData(node, parm)

        # with filter name
        else:
            parms = []
            for parm in node.parms():
                for f in parms_name_filter:
                    if hou.patternMatch(f, parm.name()) == 1:
                        parms.append(parm)
                        break
            
            self.includeParms(parms)
Exemple #22
0
    def includeParmsFromNode(self, node, parms_name_filter=None, include=True):
        '''
            Include parameters from a given hou.Node or node path object.
            Parameters can be filtered with an houdini-style pattern matching "parms_name_filter"
            which can be either a single string or a list of string.
        '''

        if not hasattr(parms_name_filter, "__iter__"):
            if parms_name_filter is None:
                parms_name_filter = []
            else:
                parms_name_filter = [parms_name_filter]

        # Check node
        node = self._convertNode(node)
        node_path = node.path()

        # Include flag
        if include:
            include_flag = ""
        else:
            include_flag = "-u"

        self.setCurrent()

        # whole node ( no filer )
        if not parms_name_filter:
            result = hou.hscript("takeinclude {0} {1} *".format(
                include_flag, node_path))
            if result[1]:
                raise TakeSetError(result[1])

            for parm in node.parms():
                self._updateSavedData(node, parm)

        # with filter name
        else:
            parms = []
            for parm in node.parms():
                for f in parms_name_filter:
                    if hou.patternMatch(f, parm.name()) == 1:
                        parms.append(parm)
                        break

            self.includeParms(parms)
Exemple #23
0
    def _getTypeColor(self, node_type):
        """Look for a color match based on the node type's name."""
        type_name = node_type.nameComponents()[2]

        # Get the category name from the node and also check the 'all'
        # category.
        categories = (node_type.category().name(), "all")

        for category_name in categories:
            # Check if the category has any entries.
            if category_name in self.nodes:
                # Check if the node type name matches any of the category
                # entries.
                for color_entry in self.nodes[category_name].itervalues():
                    if hou.patternMatch(color_entry.name, type_name):
                        return self._resolveEntry(color_entry)

        return None
Exemple #24
0
    def _getTypeColor(self, node_type):
        """Look for a color match based on the node type's name."""
        type_name = node_type.nameComponents()[2]

        # Get the category name from the node and also check the 'all'
        # category.
        categories = (node_type.category().name(), "all")

        for category_name in categories:
            # Check if the category has any entries.
            if category_name in self.nodes:
                # Check if the node type name matches any of the category
                # entries.
                for color_entry in self.nodes[category_name].itervalues():
                    if hou.patternMatch(color_entry.name, type_name):
                        return self._resolveEntry(color_entry)

        return None
    def _getToolColor(self, nodeType):
        # Get the category name from the node.
        categoryName = nodeType.category().name()

        # Check for entries for the node type category.
        if categoryName in self.tools:
            # Get any Tab menu locations the node type might show up in.
            menuLocations = _getToolMenuLocations(nodeType)

            # Process the locations, looking for the first match.
            for location in menuLocations:
                # Check if the node name is in the mapping.

                # Check if the location matches any of the category entries.
                for colorEntry in self.tools[categoryName]:
                    if hou.patternMatch(colorEntry.name, location):
                        return colorEntry.color

        return None
    def _getToolColor(self, nodeType):
        # Get the category name from the node.
        categoryName = nodeType.category().name()

        # Check for entries for the node type category.
        if categoryName in self.tools:
            # Get any Tab menu locations the node type might show up in.
            menuLocations = _getToolMenuLocations(nodeType)

            # Process the locations, looking for the first match.
            for location in menuLocations:
                # Check if the node name is in the mapping.

                # Check if the location matches any of the category entries.
                for colorEntry in self.tools[categoryName]:
                    if hou.patternMatch(colorEntry.name, location):
                        return colorEntry.color

        return None
    def set_property(self):
        """Set the property to the value.

        :return:

        """
        import hou

        # Is this property being applied to a specific render type.
        if self.rendertype is not None:
            # Get the rendertype for the current pass.
            rendertype = get_property("renderer:rendertype")

            # If the type pattern doesn't match, abort.
            if not hou.patternMatch(self.rendertype, rendertype):
                return

        _logger.debug("Setting property '%s' to %s", self.name, self.value)

        # Update the property value.
        set_property(self.name, self.value)
Exemple #28
0
    def setProperty(self):
        """Set the property to the value."""
        # Don't do anything if the property isn't enabled.
        if not self.enabled:
            return

        import mantra

        # Is this property being applied to a specific render type.
        if self.rendertype is not None:
            # Get the rendertype for the current pass.
            rendertype = mantra.property("renderer:rendertype")[0]

            # If the type pattern doesn't match, abort.
            if not hou.patternMatch(self.rendertype, rendertype):
                return

        logger.debug(
            "Setting property '{}' to {}".format(self.name, self.value)
        )

        # Update the property value.
        mantra.setproperty(self.name, self.value)
Exemple #29
0
    def _getToolColor(self, node_type):
        """Look for a color match based on the node type's Tab menu
        locations.

        """
        categories = (node_type.category().name(), "all")

        for category_name in categories:
            # Check for entries for the node type category.
            if category_name in self.tools:
                # Get any Tab menu locations the node type might show up in.
                menu_locations = _getToolMenuLocations(node_type)

                # Process the locations, looking for the first match.
                for location in menu_locations:
                    # Check if the node name is in the mapping.

                    # Check if the location matches any of the category entries.
                    for color_entry in self.tools[category_name].itervalues():
                        if hou.patternMatch(color_entry.name, location):
                            return self._resolveEntry(color_entry)

        return None
    def _get_name_style(self, node):
        """Look for a style match based on the node name.

        :param node: Node to style by name.
        :type node: hou.Node
        :return: An applicable styling object.
        :rtype: StyleConstant|StyleRule

        """
        # The node name.
        name = node.name()

        categories = (node.type().category().name(), constants.ALL_CATEGORY_KEY)

        for category_name in categories:
            # Check for rules for the node type category.
            if category_name in self.name_rules:
                # Check if the name matches any of the category rules.
                for rule in self.name_rules[category_name].itervalues():
                    if hou.patternMatch(rule.name, name):
                        return self._resolve_rule(rule)

        return None
Exemple #31
0
    def _getToolColor(self, node_type):
        """Look for a color match based on the node type's Tab menu
        locations.

        """
        categories = (node_type.category().name(), "all")

        for category_name in categories:
            # Check for entries for the node type category.
            if category_name in self.tools:
                # Get any Tab menu locations the node type might show up in.
                menu_locations = _getToolMenuLocations(node_type)

                # Process the locations, looking for the first match.
                for location in menu_locations:
                    # Check if the node name is in the mapping.

                    # Check if the location matches any of the category entries.
                    for color_entry in self.tools[category_name].itervalues():
                        if hou.patternMatch(color_entry.name, location):
                            return self._resolveEntry(color_entry)

        return None
Exemple #32
0
    def _get_name_style(self, node):
        """Look for a style match based on the node name.

        :param node: Node to style by name.
        :type node: hou.Node
        :return: An applicable styling object.
        :rtype: StyleConstant or StyleRule

        """
        # The node name.
        name = node.name()

        categories = (node.type().category().name(),
                      constants.ALL_CATEGORY_KEY)

        for category_name in categories:
            # Check for rules for the node type category.
            if category_name in self.name_rules:
                # Check if the name matches any of the category rules.
                for rule in self.name_rules[category_name].values():
                    if hou.patternMatch(rule.name, name):
                        return self._resolve_rule(rule)

        return None
Exemple #33
0
def readPattern(node, geo, child, type):
    nodePath = node.path()
    function = inspect.stack()[0][3]
    try:
        missingframe = node.evalParm("missingframe")
        skipInput = node.evalParm("skipInput")
        enableTile = node.evalParm("enableTile")
        folderSubType = node.hm().path.folderSubType(node)
        label_pattern = node.evalParm("label")
        prefix_pattern = node.evalParm("prefix")
        filePath = node.hm().path.filePath(node)

        dataList = []
        if skipInput or len(node.node("IN").inputs()) == 0:

            g_dataList = []
            if type == "cells":
                if enableTile:
                    get_cell_num = child.inputs()[2].geometry()
                    g_dataList = get_cell_num.attribValue("dataList")
                    g_dataList = [
                        str(int(c)).zfill(5) for c in g_dataList.split(',')
                    ]

                try:
                    _dataList = node.evalParm("dataList").replace(' ', '')
                    dataList = [
                        str(int(c)).zfill(5) for c in _dataList.split(',')
                    ]
                    dataList += g_dataList

                except ValueError:
                    if not g_list:
                        if missingframe == 0:
                            raise hou.NodeError("Invalid data parameter")
                        else:
                            raise hou.NodeWarning("Invalid data parameter")
                    else:
                        dataList = g_dataList

            elif type == "tiles":
                get_tile_num = child.inputs()[2].geometry()
                g_dataList = get_tile_num.attribValue("dataList")
                g_dataList = [
                    str("x" + t.replace("_", "_y"))
                    for t in g_dataList.split(',')
                ]

                if not g_dataList:
                    if missingframe == 0:
                        raise hou.NodeError("Invalid data parameter")
                    else:
                        raise hou.NodeWarning("Invalid data parameter")
                else:
                    dataList = g_dataList

        else:
            input_geo = child.inputs()[1].geometry()
            _dataList = input_geo.attribValue("dataList")
            if not _dataList:
                if missingframe == 0:
                    raise hou.NodeError(
                        "'dataList' detail attribute not found on input")
                else:
                    raise hou.NodeWarning(
                        "'dataList' detail attribute not found on input")

            if type == "cells":
                dataList = [
                    str("x" + t.replace("_", "_y"))
                    for t in _dataList.split(',')
                ]
            if type == "tiles":
                dataList = [str(int(c)).zfill(5) for c in _dataList.split(',')]

        if not dataList:
            if missingframe == 0:
                if missingframe == 0:
                    raise hou.NodeError("data parameter is empty")
                else:
                    raise hou.NodeWarning("data parameter is empty")

        try:
            dataList = list(set(dataList))
            path_root = os.path.dirname(filePath)

            if type == "cells":
                valid_files = [f for f in os.listdir(path_root) if \
                               f.split('_')[-1].split('.', 1)[0] in dataList]
            if type == "tiles":
                valid_files = [f for f in os.listdir(path_root) if \
                               f.split('.')[0][-7:] in dataList]

            for f in valid_files:

                # check if label matches
                if label_pattern and label_pattern != '*':
                    current = f.split(folderSubType + '_')[-1]

                    if type == "cells":
                        file_label = current.split("cell")[0]
                    if type == "tiles":
                        current = current.split('.', 1)[0]
                        file_label = current.replace(current[-8:], '')

                    # doesn't have label
                    if not file_label:
                        continue

                    if not hou.patternMatch(label_pattern, file_label):
                        continue

                # check if prefix matches
                if prefix_pattern and prefix_pattern != '*':
                    _p = f.split(folderSubType)[0]

                    if not _p:
                        continue

                    if not hou.patternMatch(prefix_pattern, _p):
                        continue
                file = path_root + '/' + f
                node.hm().file.load(node, geo, file)

        except WindowsError:
            print("Path error: " + filePath)

    except (KeyboardInterrupt, SystemExit):
        print("Interrupt requested of " + function + " for " + nodePath +
              "...exiting")
        return