删除指定范围内的帧


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

from pyfbsdk import *
from pyfbsdk_additions import *

try:
    from PySide2 import QtCore, QtGui, QtWidgets
except:
    from PySide import QtCore, QtGui
    from PySide import QtGui as QtWidgets


def get_animation_node(obj_node):
    anim_cuver_list = []
    for property in ['Translation', 'Rotation', 'Scaling']:
        property = eval('obj_node.{}'.format(property))
        print(property.Name)
        property.SetAnimated(True)
        
        for node in property.GetAnimationNode().Nodes:
            if node.FCurve:
                anim_cuver_list.append(node.FCurve)
    return anim_cuver_list


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(419, 127)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_3.addWidget(self.label_2)
        self.start_box = QtWidgets.QSpinBox(self.centralwidget)
        self.start_box.setMinimumSize(QtCore.QSize(66, 0))
        self.start_box.setObjectName("start_box")
        self.horizontalLayout_3.addWidget(self.start_box)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setMinimumSize(QtCore.QSize(43, 0))
        self.label.setObjectName("label")
        self.horizontalLayout_3.addWidget(self.label)
        self.end_box = QtWidgets.QSpinBox(self.centralwidget)
        self.end_box.setMinimumSize(QtCore.QSize(66, 0))
        self.end_box.setObjectName("end_box")
        self.horizontalLayout_3.addWidget(self.end_box)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.clear_but = QtWidgets.QPushButton(self.centralwidget)
        self.clear_but.setMinimumSize(QtCore.QSize(0, 30))
        self.clear_but.setObjectName("clear_but")
        self.verticalLayout.addWidget(self.clear_but)
        spacerItem1 = QtWidgets.QSpacerItem(20, 40,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 419, 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", "Clear FrameKay",
                                             None, -1))
        self.label_2.setText(QtWidgets.QApplication.translate("MainWindow",
                                                              "timeRange      Start:",
                                                              None, -1))
        self.label.setText(
            QtWidgets.QApplication.translate("MainWindow", "       End:", None,
                                             -1))
        self.clear_but.setText(
            QtWidgets.QApplication.translate("MainWindow", "Clear FrameKey",
                                             None, -1))

    def retranslateUi2(self, MainWindow):
        MainWindow.setWindowTitle(
            QtWidgets.QApplication.translate("MainWindow", "Clear FrameKay",
                                             None,
                                             QtWidgets.QApplication.UnicodeUTF8))
        self.label_2.setText(QtWidgets.QApplication.translate("MainWindow",
                                                              "timeRange      Start:",
                                                              None,
                                                              QtWidgets.QApplication.UnicodeUTF8))
        self.label.setText(
            QtWidgets.QApplication.translate("MainWindow", "       End:", None,
                                             QtWidgets.QApplication.UnicodeUTF8))
        self.clear_but.setText(
            QtWidgets.QApplication.translate("MainWindow", "Clear FrameKey",
                                             None,
                                             QtWidgets.QApplication.UnicodeUTF8))


class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.clear_but.clicked.connect(self.clear_framekey)

    def clear_framekey(self):
        start = self.start_box.value()
        end = self.end_box.value()
        selectedModels = FBModelList()
        FBGetSelectedModels(selectedModels, None, True, True)
        for obj in selectedModels:
            ani_curve_list = get_animation_node(obj)
            if not ani_curve_list:
                continue
            for ani_curve in ani_curve_list:
                ani_curve.KeyDeleteByTimeRange(FBTime(0, 0, 0, start),
                                               FBTime(0, 0, 0, end))


def get_main_qt_window():
    parent = QtWidgets.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()

评论
  目录