任何人都有一个很好的解决方案,可以在python中查询当前的maya视口渲染器(Viewport 2.0,默认视口,高质量视口)?
答案 0 :(得分: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
答案 1 :(得分:3)
此脚本返回焦点面板的渲染器:
import maya.cmds as cmds
print cmds.modelEditor( cmds.getPanel(wf=True), q=True, rnm=True )
答案 2 :(得分:0)
遍历所有模型面板,找到一个活动的面板(带有灰色轮廓) 并要求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;
}
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)