<PySide2.QtWidgets.QWidget object at 0x000000007500E048> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E088> <PySide2.QtWidgets.QWidget object at 0x000000007500E0C8> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E148> RE_GLDrawable <PySide2.QtWidgets.QWidget object at 0x000000007500E1C8> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E288> <PySide2.QtWidgets.QWidget object at 0x000000007500E2C8> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E308> RE_GLDrawable <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E348> <PySide2.QtWidgets.QWidget object at 0x000000007500E208> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E2C8> <PySide2.QtWidgets.QWidget object at 0x000000007500E288> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E348> RE_GLDrawable <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E308> <PySide2.QtWidgets.QWidget object at 0x000000007500E248> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E288> <PySide2.QtWidgets.QWidget object at 0x000000007500E2C8> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E308> RE_GLDrawable <PySide2.QtWidgets.QWidget object at 0x000000007500E3C8> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E488> <PySide2.QtWidgets.QWidget object at 0x000000007500E4C8> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E508> RE_GLDrawable <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E548> <PySide2.QtWidgets.QWidget object at 0x000000007500E408> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E448> <PySide2.QtWidgets.QWidget object at 0x000000007500E488> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E548> RE_GLDrawable <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E508> <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E348> <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E188> <PySide2.QtWidgets.QWidget object at 0x000000007500E108> RE_Window <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E188> <PySide2.QtWidgets.QWidget object at 0x000000007500E148> RE_GLDrawableWrapper <PySide2.QtWidgets.QWidget object at 0x000000007500E248> RE_GLDrawable <PySide2.QtWidgets.QVBoxLayout object at 0x000000007500E1C8>
<scriptItemid="h.native_open"> <label>Native Open...</label> <scriptCode><![CDATA[ import hou from PySide2 import QtWidgets path, _ = QtWidgets.QFileDialog.getOpenFileName( None, caption=u"读取 hip 文件", filter="*;;*.hip;;*.hip*;;*.hiplc;;*.hipnc",selectedFilter ="*.hip*" ) if path: hou.hipFile.load(path) ]]></scriptCode> </scriptItem>
<!-- ...省略... -->
<scriptItemid="h.native_save"> <label>Native Save As...</label> <scriptCode><![CDATA[ import hou from PySide2 import QtWidgets path, _ = QtWidgets.QFileDialog.getSaveFileName( None, caption=u"保存 hip 文件", filter="*;;*.hip;;*.hip*;;*.hiplc;;*.hipnc",selectedFilter ="*.hip*" ) if path: hou.hipFile.save(path) ]]></scriptCode> </scriptItem>
为了代码运行不出错,需要确保代码前面没有缩进。 如果想让 xml 看起来更整洁,可以用 exec 运行字符串的方式,字符串的多余缩进可以用 from textwrap import dedent 来解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<scriptItemid="h.native_save"> <label>Native Save As...</label> <scriptCode><![CDATA[from textwrap import dedent;exec(dedent( ur""" import hou from PySide2 import QtWidgets path, _ = QtWidgets.QFileDialog.getSaveFileName( None, caption=u"保存 hip 文件", filter="*;;*.hip;;*.hip*;;*.hiplc;;*.hipnc",selectedFilter ="*.hip*" ) if path: hou.hipFile.save(path) """)) ]]></scriptCode> </scriptItem>
通过 ; 也可以解决 Python 的换行,只是官方不推荐,因为代码挤在一起会破坏可读性,这里用了一个分号来换行 可以避免 xml 缩进被破坏。 字符串前加了 ur ,其中 u 代表 unicode 字符串,确保中文显示不会变乱码, r 代表 raw ,确保不会对字符串进行转义,避免代码有 \ 之类的路径导致转义出错,这样直接贴代码也不用担心出问题。 使用效果如下↓↓↓