首页 > 解决方案 > 如何使用 Python 在 Maya 2017 中将选定对象添加到 renderLayerSetup?

问题描述

我正在尝试编写 Python 代码以仅在 Maya 中渲染选定对象,并想知道如何在 Maya 2017 中将选定对象添加到 renderLayerSetup ?

我尝试使用我找到的一些代码

import maya.app.renderSetup.model.renderSetup as renderSetup
rs = renderSetup.instance()
test = rs.createRenderLayer('render')
scene_Assets = test.createCollection('scene_Assets')
scene_Assets.getSelector().setPattern('name')

但是这段代码要求我使用对象名称添加到集合中

我希望输出能够将对象添加到集合中,而无需重命名所有名称。

标签: pythonmaya

解决方案


有点旧线程,只是偶然发现它,因为我正在谷歌搜索解决我自己的小头痛的方法,并认为我可能会有所帮助。(如果有人对如何获取集合中的集合对象有任何提示,请给我留言。我可以找到的模式,但不是通过添加或拖放添加的模式。)

无论如何,我实际上对编程有点陌生,所以这可能不是最佳解决方案,但它适用于 Maya 2018.6(上述答案对我不起作用),所以它可能对某人有所帮助:

import maya.app.renderSetup.model.renderSetup as renderSetup
import maya.cmds as mc

rs = renderSetup.instance()

#taking the selection and bring it through a for loop to format it.
selectionLi = mc.ls(sl=1)
selection=""
for each in selectionLi:
    selection += each +", "

test = rs.createRenderLayer('render')
scene_Assets = test.createCollection('scene_Assets')
scene_Assets.getSelector().setPattern(str(selection))

推荐阅读