昨天后期来了事情,解算的外包回来了,总共100多个模型,想一个个拾取解算的布料bs,重复工作时间太长,今天结合qt写了个带ui的小脚本
用来批量关联一对一关联bs的,功能可能有点简单,逻辑也很弱智, 必须按顺序选择才行,建议一次不要选太多。
功能 20行
ui 60多行 第一次用pt ,偷懒的话,用maya自带cmds 可能十多行就结束了
#encoding = utf-8
# 冬马kazusa
# qq240077486
# 批量一对一创建blendshape测试
import maya.cmds as cmds
import pymel.core as pm
import sys
try:
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
is_maya_2020 = False
except:
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
is_maya_2020 = True
'''先创建一个空列表,然后创建ls变量,for循环一个个加载进去'''
def ls_mesh_target(**kwargs ):
box_list = []
sel = cmds.ls(sl = 1)
for i in sel:
box_list.append(i)
print box_list
def ls_mesh_bs(**kwargs):
Sphere_list = []
Sphere_sel = cmds.ls(sl = 1)
for se in Sphere_sel:
Sphere_list.append(se)
print Sphere_list
def make_bs_list(**kwargs):
i = 0 # 创个变量 为了加进字符串里面
# for循环里加入zip,可以同时循环迭代两个列表
for box, Sphere in zip(box_list, Sphere_list):
print box, Sphere
cmds.blendShape(box_list[i], Sphere_list[i],tc=0,w=[(0,1)])
i = i + 1
''' 下面是ui界面'''
class BSwindow(QWidget):
def __init__(self):
super(BSwindow,self).__init__()
self.setWindowTitle('MaKe_bs')
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint| Qt.WindowStaysOnTopHint) #窗口保持在桌面顶部
self.resize(300, 200)
self._last_mouse_pos = None
self._current_mouse_pos = None
self._is_moving = False
def mousePressEvent(self, event):
if event.button()==Qt.LeftButton:
self.m_flag=True
self.m_Position=event.globalPos()-self.pos() #获取鼠标相对窗口的位置
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor)) #更改鼠标图标
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_flag:
self.move(QMouseEvent.globalPos()-self.m_Position)#更改窗口位置
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag=False
self.setCursor(QCursor(Qt.ArrowCursor))
# 创建代码子布局控件
btn_1 = QPushButton(u'1: 选择目标体')
btn_2 = QPushButton(u'2: 选择bs模型')
btn_3 = QPushButton(u'3: 批量创建bs')
btn_3.setStyleSheet('background:red')
#连接函数
btn_1.clicked.connect(ls_mesh_target)
btn_2.clicked.connect(ls_mesh_bs)
btn_3.clicked.connect(make_bs_list)
# 创建控件代码
main_layout = QVBoxLayout() # 对象指定为窗口的布局
main_layout.setSpacing(0)
main_layout.setContentsMargins(0, 0, 0, 0) # 设置上下左右留空
self.setLayout(main_layout) # 创建布局中添加控件命令
main_layout.addSpacerItem(QSpacerItem(1, 1, QSizePolicy.Fixed, QSizePolicy.Expanding))
main_layout.addWidget(btn_1)
main_layout.addWidget(btn_2)
main_layout.addWidget(btn_3)
main_layout.addSpacerItem(QSpacerItem(1, 1, QSizePolicy.Fixed, QSizePolicy.Expanding))
if __name__ == '__main__':
if is_maya_2020:
w = BSwindow()
w.show()
else:
app = QApplication(sys.argv)
print(sys.argv)
w = BSwindow()
w.show()
sys.exec_(app.exec_())