上篇博客写到创建自定义菜单但是当我把Substance Designer的关于python的环境变量添加到程序当中的时候发现创建了两个菜单并且两个菜单是相同的。于是开始找原因,不过在翻帮助文档的时候突然发现一个比较有用的信息,也就是把菜单当作插件来加载以及卸载这个问题就彻底解决了。于是就有了下面的codes:
# -*- encoding: utf-8 -*-
import sd
from PySide2 import QtWidgets
# Get the application and the UI Manager.
app = sd.getContext().getSDApplication()
uiMgr = app.getQtForPythonUIMgr()
def say_hello():
print("Say hello")
def initializeSDPlugin():
# Function that will be called when our menu item is selected.
# Create a new menu.
menu = uiMgr.newMenu(menuTitle="MCC-Tools", objectName="doc.example.my_menu")
# Create a new action.
act = QtWidgets.QAction("export texture", menu)
act.triggered.connect(say_hello)
# Add the action to the menu.
menu.addAction(act)
def uninitializeSDPlugin():
"""unload the sd plugin"""
menu = uiMgr.findMenuFromObjectName("doc.example.my_menu")
if menu:
menu.deleteLater()
当然了,如果需要卸载,就直接在Substance Designer 插件管理器中直接卸载就可以了,卸载方式和Maya插件管理器卸载方式相同。