Ejemplo n.º 1
0
    def select_file(self):
        """ Maya Open Dialog to select file texture """
        self.open_dialog_visible = True

        if MTTSettings.value('browserFirstStart'):
            image_dir = cmds.optionVar(query='MTT_browserStartFolder')
        else:
            image_dir = cmds.workspace(query=True,
                                       rootDirectory=True) + cmds.workspace(
                fileRuleEntry='sourceImages')
            MTTSettings.set_value('browserFirstStart', True)

        file_path = cmds.fileDialog2(fileMode=1, startingDirectory=image_dir,
                                     caption='Select a texture',
                                     okCaption='Select')

        if file_path:
            new_path = file_path[0]
            cmds.optionVar(
                sv=['MTT_browserStartFolder', os.path.dirname(new_path)])
            if MTTSettings.value('forceRelativePath'):
                new_path = convert_to_relative_path(new_path)
                # relative_path = workspace(projectPath=new_path)
                # if relative_path != new_path:
                #     new_path = '/%s' % relative_path
            self.line_edit.setText(new_path)
        self.open_dialog_visible = False
        self.close()
        self.editingFinished.emit()
        cmds.showWindow(WINDOW_NAME)
Ejemplo n.º 2
0
    def select_file(self):
        """ Maya Open Dialog to select file texture """
        self.open_dialog_visible = True

        if MTTSettings.value('browserFirstStart'):
            image_dir = cmds.optionVar(query='MTT_browserStartFolder')
        else:
            image_dir = cmds.workspace(query=True,
                                       rootDirectory=True) + cmds.workspace(
                                           fileRuleEntry='sourceImages')
            MTTSettings.set_value('browserFirstStart', True)

        file_path = cmds.fileDialog2(fileMode=1,
                                     startingDirectory=image_dir,
                                     caption='Select a texture',
                                     okCaption='Select')

        if file_path:
            new_path = file_path[0]
            cmds.optionVar(
                sv=['MTT_browserStartFolder',
                    os.path.dirname(new_path)])
            if MTTSettings.value('forceRelativePath'):
                new_path = convert_to_relative_path(new_path)
                # relative_path = workspace(projectPath=new_path)
                # if relative_path != new_path:
                #     new_path = '/%s' % relative_path
            self.line_edit.setText(new_path)
        self.open_dialog_visible = False
        self.close()
        self.editingFinished.emit()
        cmds.showWindow(WINDOW_NAME)
def create_nodes(define_path='', define_type=None):
    dialog = MTTFilterFileDialog(define_path=define_path,
                                 define_type=define_type)

    if dialog.exec_():
        files = dialog.get_selected_files()
        node_type = dialog.get_node_type()
        node_attr = [
            attr for (n_type, nice, attr) in MTTSettings.SUPPORTED_TYPE
            if node_type == n_type
        ][0]

        current_selection = cmds.ls(selection=True)
        MTTSettings.set_value('suspendRenameCallbacks', True)

        nodes = list()
        for f in files:
            n_name = os.path.basename(f).rsplit('.')[0]
            node_name = n_name if not n_name[0].isdigit() else '_%s' % n_name
            new_node = cmds.shadingNode(node_type, name=node_name, asTexture=1)
            convert = MTTSettings.value('forceRelativePath')

            if convert:
                f = convert_to_relative_path(f)

            set_attr(new_node, node_attr, f, attr_type='string')

            if MTTSettings.IMPORT_POLICY:
                try:
                    exec MTTSettings.IMPORT_POLICY
                    exec_import_policy(current_selection, node_name,
                                       os.path.basename(f))

                except RuntimeError:
                    mtt_log('Fail to run import policy.',
                            msg_type='error',
                            verbose=False)

            nodes.append(new_node)

        MTTSettings.set_value('suspendRenameCallbacks', False)
        MTTSettings.remove('suspendRenameCallbacks')
        if nodes:
            cmds.select(nodes, replace=True)

    dialog.deleteLater()
def create_nodes(define_path='', define_type=None):
    dialog = MTTFilterFileDialog(
        define_path=define_path, define_type=define_type)

    if dialog.exec_():
        files = dialog.get_selected_files()
        node_type = dialog.get_node_type()
        node_attr = [
            attr
            for (n_type, nice, attr) in MTTSettings.SUPPORTED_TYPE
            if node_type == n_type][0]

        current_selection = cmds.ls(selection=True)
        MTTSettings.set_value('suspendRenameCallbacks', True)

        nodes = list()
        for f in files:
            n_name = os.path.basename(f).rsplit('.')[0]
            node_name = n_name if not n_name[0].isdigit() else '_%s' % n_name
            new_node = cmds.shadingNode(node_type, name=node_name, asTexture=1)
            convert = MTTSettings.value('forceRelativePath')

            if convert:
                f = convert_to_relative_path(f)

            set_attr(new_node, node_attr, f, attr_type='string')

            if MTTSettings.IMPORT_POLICY:
                try:
                    exec MTTSettings.IMPORT_POLICY
                    exec_import_policy(
                        current_selection, node_name, os.path.basename(f)
                    )

                except RuntimeError:
                    mtt_log('Fail to run import policy.', msg_type='error',
                            verbose=False)

            nodes.append(new_node)

        MTTSettings.set_value('suspendRenameCallbacks', False)
        MTTSettings.remove('suspendRenameCallbacks')
        if nodes:
            cmds.select(nodes, replace=True)

    dialog.deleteLater()