[英]Can I script an equivalent of “Delete All by Type” in Maya's Hypershade?
[英]python + maya: Graph selected node's shaders to hypershade network
我編寫了一個腳本,該腳本獲取選定對象正在使用的着色器。 然后,我想在Hypershade中將這些着色器繪制到網絡。 我在這里想念什么?
我設法使它在這個小片段上起作用,但在主要代碼上卻沒有...
小測試代碼段:
import maya.cmds as cmds
blinn = cmds.createNode('blinn')
cmds.hyperShade(blinn)
主要代碼:
import maya.cmds as cmds
# get selected nodes:
nodes = cmds.ls(selection=True, dag=True)
nodeCount = len(nodes)
# get shading groups from shapes:
if nodeCount >= 1:
shadingGroups = cmds.listConnections(nodes, t='shadingEngine')
shadingGroupsCount = len(shadingGroups)
# get the shaders:
if shadingGroupsCount >= 1:
shaders = cmds.ls(cmds.listConnections(shadingGroups), materials=1)
# graph shaders to the network in the hypershade:
if shaders >= 1:
cmds.hyperShade(shaders)
print shaders
從我可以從您的代碼確定的結果來看,您正在選擇對象的材料。
因此,這將遍歷對象並將其着色器添加到圖形中。 最初,它將在開始添加之前清除圖形,您可以通過簡單地清除標志resetGraph=True, dependGraphArea=True
來刪除該功能。
import maya.cmds as cmds
import maya.mel as mel
nodes = cmds.ls(selection=True, dag=True)
## Open the panel, doesn't re-open if already up and sets focus
cmds.HypershadeWindow()
## Get the name of the hsPanel
hsPanel = cmds.getPanel(withFocus=True)
## Clear the graph
cmds.hyperShade(resetGraph=True, dependGraphArea=True)
for node in nodes:
if len(nodes) > 0:
## Select a node
cmds.select(node, r=1)
## List the materials assigned to the object
cmds.hyperShade(shaderNetworksSelectMaterialNodes=1)
## Create an array of the materials
materialSelection = cmds.ls(sl=1)
## Loop over the materials and graph them
for material in materialSelection:
# cmds.select(material, r=1)
try:
cmds.hyperGraph(hsPanel, edit=True, addDependNode=material)
except:
mel.eval("hyperShadePanelGraphCommand(\"%s\", \"addSelected\")" % hsPanel)
else:
cmds.warning("Please select an object")
我對使用mel eval語句hyperShadePanelGraphCommand()
,但是我找不到python的替代品。 很高興有人糾正它!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.