任何人都有一个很好的解决方案来查询python中当前的maya视口渲染器(视口2.0,默认视口,高质量视口)?
问问题
6954 次
3 回答
5
@Tomek 的答案将完全有效。如果你要走 PyMEL 路线,你可以这样做:
import pymel.core.uitypes as pmui
model_panel = pmui.ModelEditor(pm.getPanel(withFocus=True))
print pmui.ModelEditor.getRendererName(model_panel)
虽然,那个片段似乎是喜怒无常的。它有时会抛出一个错误,抱怨找不到模型编辑器,尤其是从架子上执行时。
另一种方法会有点罗嗦,但它每次都有效:
import pymel.core as pm
import pymel.core.uitypes as pmui
modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)
for modelPanel in modelPanelList:
if pmui.ModelEditor(modelPanel).getActiveView():
try:
# Always better to try in the case of active panel operations
# as the active panel might not be a viewport.
print pmui.ModelEditor(modelPanel).getRendererName()
except Exception as e:
# Handle exception
print e
一种简洁的伪 PyMEL 方法是 PyMEL-ify Tomek 的答案:
import pymel.core as pm
print pm.modelEditor(pm.getPanel(wf=True), q=True, rnm=True)
要获取视口渲染器列表:
import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererList()
这是关于模型编辑器和视口渲染器的一些额外信息。要获得他们的“友好”名称:
import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererListUI()
简而言之,要设置它们,我会使用 PyMEL 并执行以下操作:
import pymel.core.uitypes as pmui
# assuming you know which modelPanel you want to affect
pmui.ModelEditor("modelPanel4").setRendererName("ogsRenderer")
要影响所有视口(modelPanels),我会这样做:
import pymel.core as pm
import pymel.core.uitypes as pmui
modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)
for modelPanel in modelPanelList:
pmui.ModelEditor(modelPanel).setRendererName("ogsRenderer")
只影响焦点中的视口:
import pymel.core as pm
import pymel.core.uitypes as pmui
modelPanelList = []
modelEditorList = pm.lsUI(editors=True)
for myModelPanel in modelEditorList:
if myModelPanel.find('modelPanel') != -1:
modelPanelList.append(myModelPanel)
for modelPanel in modelPanelList:
if pmui.ModelEditor(modelPanel).getActiveView():
try:
# Always better to try in the case of active panel operations
# as the active panel might not be a viewport.
pmui.ModelEditor(modelPanel).setRendererName("ogsRenderer")
except Exception as e:
# Handle exception
print e
于 2014-12-04T12:46:43.277 回答
3
此脚本返回焦点面板的渲染器:
import maya.cmds as cmds
print cmds.modelEditor( cmds.getPanel(wf=True), q=True, rnm=True )
于 2014-12-04T12:05:12.897 回答
1
遍历所有模型面板,找到一个激活的(带有灰色轮廓)并请求 rendereName(rnm)
梅尔:
// find current modelEditor
string $cur_mp;
for ($mp in `getPanel -typ "modelPanel"`){
// check if active
if (`modelEditor -q -av $mp`){
$cur_mp = $mp;
break;
}
}
if ($cur_mp != ""){
// your coude next
print $cur_mp;
$new_rndr = "ogsRenderer";
// set new renderer
modelEditor -e -rnm $new_rndr $cur_mp;
}
py:
import maya.cmds as cm
cur_mp = None
for mp in cm.getPanel(type="modelPanel"):
if cm.modelEditor(mp, q=1, av=1):
cur_mp = mp
break
if cur_mp:
# do your stuff
print cur_mp
new_rndr = "ogsRenderer"
cm.modelEditor(cur_mp, e=1, rnm=new_rndr)
皮梅尔:
import pymel.core as pm
# maybe its not the best solution to iterate over all existing modelPanels
mp_ls = [x
for x in pm.lsUI()
if type(x).__name__ == "ModelEditor"
and type(x.getParent()).__name__ == "PyUI"
and x.getActiveView()]
if mp_ls:
# do your stuff
print mp_ls[0] # current modelEditor
new_rndr = "ogsRenderer"
mp_ls[0].setRendererName(new_rndr)
于 2018-11-27T13:38:38.637 回答