def rename_item(self): file_name, ok = QtWidgets.QInputDialog.getText( self, 'Rename', 'Enter the new name:', QtWidgets.QLineEdit.Normal) if not ok: OpenMaya.MGlobal.displayWarning('#Abrot your rename!...') return if not self.listwidget.selectedItems(): OpenMaya.MGlobal.displayWarning('\nNo selection') return current_item = self.listwidget.selectedItems()[-1] if str(current_item.text()) not in self.bundles: OpenMaya.MGlobal.displayWarning( '\nCorresponding weight not found %s' % current_item.text()) return rw = readWrite.ReadWrite(t='weights') weight_path = self.bundles[str(current_item.text())]['path'] new_weight_path = os.path.join(os.path.dirname(weight_path), '%s.%s' % (file_name, rw.extention)) try: os.chmod(weight_path, 0777) os.rename(weight_path, new_weight_path) replay = 1 except Exception as error: warnings.warn('\n%s' % str(error), Warning) self.load_weigts() OpenMaya.MGlobal.displayInfo('Rename Done!...')
def exports(self): selections = self.my_maya.getSelectedDagPaths() drivers = {} for index in range(selections.length()): if not selections[index].isValid(): continue tag = None if self.my_maya.hasJoint(selections[index]): tag = 'skincluster' elif self.my_maya.hasCluster(selections[index]): tag = 'cluster' drivers.setdefault(tag, []).append(selections[index]) if None in drivers: OpenMaya.MGlobal.displayError( '#Unwanted nodes are found in your selection') return if drivers.keys().count(drivers.keys()[0]) != len(drivers.keys()): OpenMaya.MGlobal.displayError( '#You selected differ types of nodes\nselect cluster handless either joints' ) return file_name, ok = QtWidgets.QInputDialog.getText( self, 'Weight Export', 'Enter the weight name:', QtWidgets.QLineEdit.Normal) if not ok: OpenMaya.MGlobal.displayWarning('#Abrot your export!...') return weights = {} if drivers.keys()[0] == 'cluster': weights = self.cluster.get_weights(drivers['cluster']) if drivers.keys()[0] == 'skincluster': weights = self.skincluster.get_weights(drivers['skincluster']) comment = 'smart tool 0.0.1 - weights container' created_date = datetime.now().strftime('%B/%d/%Y - %I:%M:%S:%p') description = 'This data contain information about maya 2016 deformers weights' type = 'weights' valid = True data = weights tag = drivers.keys()[0] rw = readWrite.ReadWrite(c=comment, cd=created_date, d=description, t=type, v=valid, data=data, tag=tag) rw.create(name=str(file_name)) print rw.file_path self.load_weigts() OpenMaya.MGlobal.displayInfo('Export {} weights Done!...'.format( drivers.keys()[0]))
def load_weigts(self): self.listwidget.clear() rw = readWrite.ReadWrite(t='weights') self.bundles = rw.getBundles() for each_bundle, bundle_data in self.bundles.items(): item = QtWidgets.QListWidgetItem() item.setText(each_bundle) current_icon = os.path.join(resources.getIconPath(), '{}.png'.format(bundle_data['tag'])) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(current_icon), QtGui.QIcon.Normal, QtGui.QIcon.Off) item.setIcon(icon) item.setToolTip('\n'.join(bundle_data['data'].keys())) self.listwidget.addItem(item)