python+maya:将选定节点的着色器绘制到hypershade n

2024-05-06 13:10:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个脚本,它可以获取选定对象正在使用的着色器。然后,我要将这些着色器绘制到“hypershade”中的网络。我错过了什么?在

我设法让它工作在这个小片段,但不是在主要的代码。。。在

小测试片段:

import maya.cmds as cmds
blinn = cmds.createNode('blinn')
cmds.hyperShade(blinn)

主代码:

^{pr2}$

Tags: 对象代码import网络脚本as绘制着色器
4条回答

从你的代码中我可以确定的是,你在寻找select对象的材质。在

因此,这将循环覆盖对象并将其着色器添加到图形中。最初,它将在开始添加之前清除图形,您可以通过简单地清除标志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的替代品。很高兴有人能纠正这一点!

相关问题 更多 >