def setData(self, index, value, role=Qt.EditRole): """ Update data from model :param index: :param value: :param role: :return: """ if index.isValid() and 0 <= index.row() < self.rowCount(): texture = self.textures[index.row()] name = texture[0] column = index.column() if column == NODE_NAME: wanted_name = value if wanted_name: new_name = self.rename_maya_node(name, wanted_name) state = new_name != name if state: self.request_sort() return state else: return False elif column == NODE_FILE: node_type = cmds.nodeType(name) attr = self.supported_format_dict[node_type] set_attr(name, attr, value, attr_type='string') self.request_sort() return True return False
def set_database_node_and_attribute(self, node_name, node_attr_value): """ Set absolute or relative file path """ node_attr = self.supported_format_dict[cmds.nodeType(node_name)] set_attr(node_name, node_attr, node_attr_value, attr_type='string') c = self.db.cursor() c.execute('UPDATE NodesTable SET Attribute=? WHERE Name=?', (node_attr_value, node_name))
def set_database_node_and_attribute(self, node_name, node_attr_value): """ Set absolute or relative file path """ node_attr = self.supported_format_dict[cmds.nodeType(node_name)] set_attr(node_name, node_attr, node_attr_value, attr_type='string') c = self.db.cursor() c.execute( 'UPDATE NodesTable SET Attribute=? WHERE Name=?', (node_attr_value, node_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()
def file_watch_file_change(self, file_path): key_path = self.convert_to_key_path(file_path) c = self.db.cursor() if MTTSettings.value('autoReload'): self.is_reloading_file = True c.execute( 'SELECT Name ' 'FROM NodesTable LEFT JOIN FilesTable USING(FileId) ' 'WHERE KeyPath=?', (key_path, )) nodes = c.fetchall() for node in [x[0] for x in nodes]: attr_name = self.supported_format_dict[cmds.nodeType(node)] attr_value = cmds.getAttr('%s.%s' % (node, attr_name)) set_attr(node, attr_name, attr_value, attr_type='string') self.is_reloading_file = False self.file_watch_add_path(file_path) new_state = self.get_file_state(file_path) c.execute('UPDATE FilesTable SET State=? WHERE KeyPath=?', (new_state, key_path)) self.request_sort()