**
文章目录
相关网址及本地doc
插件 — Plugins (pixyz-software.com)
Introduction – Pixyz API Reference (pixyz-software.com)
C:/Users/Admin/AppData/Roaming/PiXYZStudio/doc/index.html
简介
pixyz 插件有两部分组成:由py文件组成的脚本和由xml文件组成的界面,其中没有xml文件,pixyz不会检测到这个插件
插件文件必须放置在计算机上的ProgramData
(%programdata%/PixyzStudio/plugins)文件夹或者AppData
(%appdata%/PixyzStudio/plugins)文件夹下
编写代码
python文件示例:
def MergeByFloor(merge,structureList):
#先合并最终极使所选单位减少
#scene.mergeFinalLevel([1], 1, False)
#遍历结构列表
if len(structureList)==0:
return
for structure in structureList :
#有后缀,走这一步
if structure.Suffix:
#组合所输入楼层名
floors = [structure.FloorPrefix+"{:02}".format(i) for i in range(structure.Start, structure.End+1)]
print(floors)
#遍历楼层
for floor in floors:
#按照元数据查找楼层物体
OccurrenceList=scene.findByMetadata("Text/所属楼层", floor, [])
if len(OccurrenceList)==0:
continue
#如果选择合并
if merge:
OccurrenceList=MergeParts(OccurrenceList)
MoveToOccurrence(OccurrenceList,1)
ReName(OccurrenceList,floor)
else:
MoveToOccurrence(OccurrenceList,scene.createOccurrence(floor,1))
#无后缀,走这一步
else:
floor = structure.FloorPrefix
OccurrenceList=scene.findByMetadata("Text/所属楼层", floor, [])
if len(OccurrenceList)==0:
continue
if merge:
OccurrenceList=MergeParts(OccurrenceList)
MoveToOccurrence(OccurrenceList,1)
ReName(OccurrenceList,floor)
else:
MoveToOccurrence(OccurrenceList,scene.createOccurrence(floor,1))
def MoveToOccurrence(OccurrenceList, Occurrence):
if len(OccurrenceList) == 0 :
OccurrenceList = scene.getSelectedOccurrences()
if Occurrence == 0 :
Occurrence = 1
scene.moveOccurrences(OccurrenceList,Occurrence)
def ReName(OccurrenceList, Name):
for Occurrence in OccurrenceList :
final=core.setProperty(Occurrence,"Name",Name)
def MergeParts(OccurrenceList):
if len(OccurrenceList) == 0 :
OccurrenceList = scene.getSelectedOccurrences()
OccurrenceList=scene.mergePartsByMaterials(OccurrenceList,True,1)
OccurrenceList = scene.mergeParts(OccurrenceList, 1)
scene.movePivotPointToSelectionCenter(OccurrenceList)
return OccurrenceList
xml文件示例:
<?xml version="1.0" encoding="utf-8" ?>
<module name="MergeByFloor2020" version="1.0">
<include module="Core"/>
<include module="Scene"/>
<decltype name="Structure">
<struct>
<field name="Suffix" type="Bool" displayName="Suffix" default="True"/>
<field name="FloorPrefix" type="String" displayName="Floor Prefix" default="F"/>
<field name="Start" type="Int" displayName="Start" default="1"/>
<field name="End" type="Int" displayName="End" default="4"/>
</struct>
</decltype>
<decltype name="StructureList">
<list type="Structure"/>
</decltype>
<function name="MergeByFloor" state="Stable" scriptable="true" guiable="true" description="" logName="" scriptFile="MergePartsPluginsScript.py" toolbar="none" static="true">
<parameters>
<parameter name="merge" displayName="是否合并" type="Bool" default="True" state="Stable"/>
<parameter name="structureList" displayName="楼层列表(是否有后缀,楼层前缀,开始楼层,结束楼层)" type="StructureList" state="Stable"/>
</parameters>
<disableLogger/>
</function>
<function name="MoveToOccurrence" state="Stable" scriptable="true" guiable="false" description="" logName="" scriptFile="MergePartsPluginsScript.py">
<parameters>
<parameter name="OccurrenceList" displayName="物体列表(默认场景中已选择的物体)" type="OccurrenceList" state="Stable"/>
<parameter name="Occurrence" displayName="父节点(默认根节点)" type="Occurrence" state="Stable"/>
</parameters>
</function>
</module>
在这个py中,写具体的实现逻辑,我们可以看到第一个和第二个方法都在xml文件中用function标签中定义了,所以可以在插件菜单中渲染出来,而第三第四个方法没有在xml中定义,所以没有渲染
重点在function标签内,这部分定义了用户界面的显示,在parameter标签内,定义了用户界面内显示的属性。这里定义了一个显示名称为是否合并的布尔类型属性和一个显示名称为楼层列表的自定义结构列表
在具体实现逻辑中,可以查询官网中api参考**