重命名工具


# -*- coding: UTF-8 -*-

from pyfbsdk import *
from pyfbsdk_additions import *
import os.path
import math

try:
    from PySide.QtCore import *
    from PySide.QtGui import *
    from PySide import shiboken
    from PySide import QtGui as QtWidgets
except:
    from PySide2.QtWidgets import *
    from PySide2.QtCore import *
    from PySide2.QtGui import *
    import shiboken2 as shiboken

    from PySide2 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(407, 154)
        MainWindow.setStyleSheet("")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.btn_PlotSelectedTakes = QtWidgets.QPushButton(self.centralwidget)
        self.btn_PlotSelectedTakes.setStyleSheet("")
        self.btn_PlotSelectedTakes.setObjectName("btn_PlotSelectedTakes")
        self.verticalLayout.addWidget(self.btn_PlotSelectedTakes)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.btn_renameTakes = QtWidgets.QPushButton(self.centralwidget)
        self.btn_renameTakes.setStyleSheet("")
        self.btn_renameTakes.setObjectName("btn_renameTakes")
        self.horizontalLayout.addWidget(self.btn_renameTakes)
        self.le_renameTakesA = QtWidgets.QLineEdit(self.centralwidget)
        self.le_renameTakesA.setObjectName("le_renameTakesA")
        self.horizontalLayout.addWidget(self.le_renameTakesA)
        self.le_renameTakesB = QtWidgets.QLineEdit(self.centralwidget)
        self.le_renameTakesB.setObjectName("le_renameTakesB")
        self.horizontalLayout.addWidget(self.le_renameTakesB)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.btn_ClipboardCopy = QtWidgets.QPushButton(self.centralwidget)
        self.btn_ClipboardCopy.setStyleSheet("")
        self.btn_ClipboardCopy.setObjectName("btn_ClipboardCopy")
        self.horizontalLayout_2.addWidget(self.btn_ClipboardCopy)
        self.btn_ClipboardPaste = QtWidgets.QPushButton(self.centralwidget)
        self.btn_ClipboardPaste.setStyleSheet("")
        self.btn_ClipboardPaste.setObjectName("btn_ClipboardPaste")
        self.horizontalLayout_2.addWidget(self.btn_ClipboardPaste)
        self.btn_ClipboardPaste_rename = QtWidgets.QPushButton(
            self.centralwidget)
        self.btn_ClipboardPaste_rename.setStyleSheet("")
        self.btn_ClipboardPaste_rename.setObjectName(
            "btn_ClipboardPaste_rename")
        self.horizontalLayout_2.addWidget(self.btn_ClipboardPaste_rename)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        spacerItem = QtWidgets.QSpacerItem(20, 40,
                                           QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 407, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        try:
            self.retranslateUi1(MainWindow)
        except:
            self.retranslateUi2(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi1(self, MainWindow):
        MainWindow.setWindowTitle(
            QtWidgets.QApplication.translate("MainWindow", "MainWindow", None, -1))
        self.btn_PlotSelectedTakes.setText(
            QtWidgets.QApplication.translate("MainWindow",
                                             "Plot Selected Takes to Control Rig", None, -1))
        self.btn_renameTakes.setText(
            QtWidgets.QApplication.translate("MainWindow", "Replace", None, -1))
        self.btn_ClipboardCopy.setText(
            QtWidgets.QApplication.translate("MainWindow", "Copy/Clipboard", None, -1))
        self.btn_ClipboardPaste.setText(
            QtWidgets.QApplication.translate("MainWindow", "Paste/Takes", None, -1))
        self.btn_ClipboardPaste_rename.setText(
            QtWidgets.QApplication.translate("MainWindow", "Rename/Takes",  None, -1))

    def retranslateUi2(self, MainWindow):
        MainWindow.setWindowTitle(
            QtWidgets.QApplication.translate("MainWindow", "MainWindow", None,
                                             QtWidgets.QApplication.UnicodeUTF8))
        self.btn_PlotSelectedTakes.setText(
            QtWidgets.QApplication.translate("MainWindow",
                                             "Plot Selected Takes to Control Rig",
                                             None, QtWidgets.QApplication.UnicodeUTF8))
        self.btn_renameTakes.setText(
            QtWidgets.QApplication.translate("MainWindow", "Replace", None,
                                             QtWidgets.QApplication.UnicodeUTF8))
        self.btn_ClipboardCopy.setText(
            QtWidgets.QApplication.translate("MainWindow", "Copy/Clipboard",
                                             None, QtWidgets.QApplication.UnicodeUTF8))
        self.btn_ClipboardPaste.setText(
            QtWidgets.QApplication.translate("MainWindow", "Paste/Takes", None,
                                             QtWidgets.QApplication.UnicodeUTF8))
        self.btn_ClipboardPaste_rename.setText(
            QtWidgets.QApplication.translate("MainWindow", "Rename/Takes",
                                             None, QtWidgets.QApplication.UnicodeUTF8))


class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.slot()
        
    def slot(self):
        self.btn_ClipboardCopy.clicked.connect(self.fn_ClipboardCopy)
        self.btn_ClipboardPaste.clicked.connect(self.fn_ClipboardPaste)
        self.btn_ClipboardPaste_rename.clicked.connect(self.fn_ClipboardPaste_rename)
        self.btn_PlotSelectedTakes.clicked.connect(self.fn_plotSelectedTakes)
        self.btn_renameTakes.clicked.connect(self.fn_renameTakes)

    def fn_ClipboardCopy(self):
        clipboard = QApplication.clipboard()
        clipText = ""

        for take in FBSystem().Scene.Takes:
            if take.Selected == True:
                if clipText == "":
                    clipText = take.Name
                else:
                    clipText = clipText + "\n" + take.Name

        clipboard.setText(clipText)
        self.mprint(clipboard.text())

    def fn_ClipboardPaste(self):
        clipboard = QApplication.clipboard()
        originalText = clipboard.text()
        ls_takeNames = originalText.split("\n")
        self.mprint(ls_takeNames)

        for takeName in ls_takeNames:
            newTake = FBTake(str(takeName))
            FBSystem().Scene.Takes.append(newTake)

    def fn_ClipboardPaste_rename(self):
        clipboard = QApplication.clipboard()
        originalText = clipboard.text()
        ls_takeNames = originalText.split("\n")

        takeName = ls_takeNames[0]
        # newTake = FBTake(str(takeName))
        for lTakeIdx in FBSystem().Scene.Components:
            if lTakeIdx.Selected:
                lTakeIdx.Name = str(takeName)

    def fn_weaponChanged(self):
        for i, item in enumerate(self.rootCurveObj.PropertyList.Find(
                "Weapon type").GetEnumStringList()):
            if item == self.shapeTypeCB.currentText():
                self.rootCurveObj.PropertyList.Find("Weapon type").Data = i

    def fn_weaponSideChanged(self):
        for i, item in enumerate(self.rootCurveObj.PropertyList.Find(
                "Weapon in hand").GetEnumStringList()):
            if item == self.cb_weaponSide.currentText():
                self.rootCurveObj.PropertyList.Find("Weapon in hand").Data = i

    def fn_renameTakes(self):
        findName = str(self.le_renameTakesA.text())
        replaceName = str(self.le_renameTakesB.text())

        for obj in FBSystem().Scene.Components:
            if obj.Selected:
                obj.Name = obj.Name.replace(findName, replaceName)

    def fn_plotSelectedTakes(self):
        lSystem = FBSystem()
        plotOptions = FBPlotOptions()
        plotOptions.ConstantKeyReducerKeepOneKey = False
        plotOptions.PlotAllTakes = False
        plotOptions.PlotOnFrame = True
        plotOptions.PlotPeriod = FBTime(0, 0, 0, 1)
        plotOptions.PlotTranslationOnRootOnly = True
        plotOptions.PreciseTimeDiscontinuities = False
        plotOptions.RotationFilterToApply = FBRotationFilter.kFBRotationFilterUnroll
        plotOptions.UseConstantKeyReducer = True

        lCharacter = FBApplication().CurrentCharacter

        for lTakeIdx in range(len(lSystem.Scene.Takes)):
            if lSystem.Scene.Takes[lTakeIdx].Selected == True:
                self.mprint(lSystem.Scene.Takes[lTakeIdx].Name)
                FBSystem().CurrentTake = lSystem.Scene.Takes[lTakeIdx]
                lCharacter.PlotAnimation(
                    FBCharacterPlotWhere.kFBCharacterPlotOnControlRig,
                    plotOptions)

    def SelectBranch(self, topModel):
        for childModel in topModel.Children:
            self.SelectBranch(childModel)
        topModel.Selected = True

    def getBranch(self, topModel, obj_list):
        for childModel in topModel.Children:
            self.getBranch(childModel, obj_list)
        if topModel != self.pChar.GetCtrlRigModel(
                FBBodyNodeId.kFBRightWristNodeId) and topModel != self.pChar.GetCtrlRigModel(
                FBBodyNodeId.kFBLeftWristNodeId):
            obj_list.append(topModel)

    def listRelatives(self, model):
        obj_list = []
        self.getBranch(model, obj_list)
        return obj_list


def get_main_qt_window():
    parent = QApplication.activeWindow()
    grand_parent = parent
    while grand_parent:
        parent = grand_parent
        grand_parent = parent.parent()
    return parent


def show():
    parent = get_main_qt_window()
    window = MainWindow(parent)
    window.show()


show()

评论
  目录