from PySide2 import QtWidgets, QtCore, QtGui
from shiboken2 import wrapInstance
from maya import OpenMayaUI as omui
import pymel.core as pm
def getMayaMainWindow():
win = omui.MQtUtil_mainWindow()
ptr = wrapInstance(long(win), QtWidgets.QMainWindow)
return ptr
def getDock(name="CopySkinWeightsDsock"):
deleteDock(name)
ctrl = pm.workspaceControl(name, dockToMainWindow=("left", 1), label="Copy Skin Weight Manager")
qtCtrl = omui.MQtUtil_findControl(ctrl)
ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)
return ptr
def deleteDock(name="CopySkinWeightsDsock"):
if pm.workspaceControl(name, query=True,exists=True):
pm.deleteUI(name)
class transferSkinWeightUI(QtWidgets.QWidget):
"""
The transferSkinWeightUI let us transfer skin weights from one object to another
"""
def __init__(self, dock = True):
if dock:
parent = getDock()
else:
deleteDock()
parent = QtWidgets.QDialog(parent=getMayaMainWindow())
parent.setObjectName("skinningManager")
parent.setWindowTitle("Copy Skin Weight Manager")
layout = QtWidgets.QVBoxLayout(parent)
super(transferSkinWeightUI, self).__init__(parent = parent)
self.buildUI()
self.parent().layout().addWidget(self)
if not dock:
parent.show()
def buildUI(self):
""" This method builds out the UI """
# This is the master layout
mainLayout = QtWidgets.QVBoxLayout(self)
tableWidget = QtWidgets.QWidget()
tableWidget.setObjectName("centralwidget")
tableLayout = QtWidgets.QHBoxLayout(tableWidget)
mainLayout.addWidget(tableWidget)
# SOURCE W info
sourceInfoWidget = QtWidgets.QWidget()
sourceInfoLayout = QtWidgets.QVBoxLayout(sourceInfoWidget)
tableLayout.addWidget(sourceInfoWidget)
sourceLabel = QtWidgets.QLabel("Source Geo")
sourceInfoLayout.addWidget(sourceLabel)
# This will create a grid widget to display our selected items
self.sourceWidget = QtWidgets.QListWidget()
self.sourceWidget.setViewMode(QtWidgets.QListWidget.ListMode)
sourceInfoLayout.addWidget(self.sourceWidget)
sourceButtonWidget = QtWidgets.QWidget()
sourceButtonLayout = QtWidgets.QHBoxLayout(sourceButtonWidget)
sourceInfoLayout.addWidget(sourceButtonWidget)
selectSourceBtn = QtWidgets.QPushButton("Import")
selectSourceBtn.clicked.connect(self.populateSourceItems)
sourceButtonLayout.addWidget(selectSourceBtn)
deselectSourceBtn = QtWidgets.QPushButton("Delete")
deselectSourceBtn.clicked.connect(self.deleteSourceItems)
sourceButtonLayout.addWidget(deselectSourceBtn)
# POST W info
postInfoWidget = QtWidgets.QWidget(tableWidget)
postInfoLayout = QtWidgets.QVBoxLayout(postInfoWidget)
tableLayout.addWidget(postInfoWidget)
postLabel = QtWidgets.QLabel("Post Geo")
postInfoLayout.addWidget(postLabel)
# This will create a grid widget to display our selected items
self.postWidget = QtWidgets.QListWidget()
self.postWidget.setViewMode(QtWidgets.QListWidget.ListMode)
postInfoLayout.addWidget(self.postWidget)
postButtonWidget = QtWidgets.QWidget()
postButtonLayout = QtWidgets.QHBoxLayout(postButtonWidget)
postInfoLayout.addWidget(postButtonWidget)
selectPostBtn = QtWidgets.QPushButton("Import")
selectPostBtn.clicked.connect(self.populatePostItems)
postButtonLayout.addWidget(selectPostBtn)
deselectPostBtn = QtWidgets.QPushButton("Delete")
deselectPostBtn.clicked.connect(self.deletePostItems)
postButtonLayout.addWidget(deselectPostBtn)
# holds bottom buttons
bottomWidget = QtWidgets.QWidget()
bottomLayout = QtWidgets.QHBoxLayout(bottomWidget)
mainLayout.addWidget(bottomWidget)
transferBtn = QtWidgets.QPushButton("Transfer")
bottomLayout.addWidget(transferBtn)
applyBtn = QtWidgets.QPushButton("Apply")
bottomLayout.addWidget(applyBtn)
closeBtn = QtWidgets.QPushButton("Close")
closeBtn.clicked.connect(self.close)
bottomLayout.addWidget(closeBtn)
def populateSourceItems(self):
sourceItems = pm.ls(sl=1)
# items currently listed in QListWidget
lst = [i.text() for i in self.sourceWidget.findItems("", QtCore.Qt.MatchContains)]
for i in sourceItems:
item = QtWidgets.QListWidgetItem("%s" % i)
self.sourceWidget.addItem(item)
def populatePostItems(self):
postItems = pm.ls(sl=1) # to which items
for i in postItems:
item = QtWidgets.QListWidgetItem("%s" % i)
self.postWidget.addItem(item)
def transferWeights(self): pass
def deleteSourceItems(self):
item = self.sourceWidget.takeItem(self.sourceWidget.currentRow())
def deletePostItems(self):
item = self.postWidget.takeItem(self.postWidget.currentRow())my apologies, is there a way I can edit original post?
Yes, that is a problem. I would not have it if I used cmds, but PyMel throws back and node type which makes it impossible to compare values between what i am getting from findItems() and pm.ls(sl=1) unless I were to remove the first part of each string which tells nodetype. I also would not have this kind of problem if I used maya API, but I am not familiar with its syntax.
Is the best solution to remove nodetype from what pm.ls(sl=1) gives me?
def populateSourceItems(self):
sourceItems = pm.ls(sl=1)
# items currently listed in QListWidget
lst = [i.text() for i in self.sourceWidget.findItems("", QtCore.Qt.MatchContains)]
for i in sourceItems:
item = QtWidgets.QListWidgetItem("%s" % i)
self.sourceWidget.addItem(item)
# items currently listed in QListWidget
existing = set(i.text() for i in self.sourceWidget.findItems("", QtCore.Qt.MatchContains))
for i in sourceItems:
text = str(i)
if text in existing:
continue
item = QtWidgets.QListWidgetItem(text)
item.setData(QtCore.Qt.UserRole, i)
self.sourceWidget.addItem(item)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2efd9ddf-1f61-4b4b-8c44-86191a81d8ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
amazing! At first I tried going through both list with zip() to find differences. That's where I failed.
I must say that UserRole is something I have not heard about thus far. I will have to look into it. Thank you very much for teaching me!
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8ea5377d-ab07-4666-aaa5-3b5ce7bf2d30%40googlegroups.com.