任何人都有一個很好的解決方案來查詢python中當(dāng)前的maya視口渲染器(Viewport 2.0,默認視口,高質(zhì)量視口)? 解決方法: @Tomek的答案將完美無缺.如果你要去PyMEL路線,你可以這樣做:
import pymel.core.uitypes as pmui
model_panel = pmui.ModelEditor(pm.getPanel(withFocus=True))
print pmui.ModelEditor.getRendererName(model_panel)
雖然,那個片段似乎很有氣質(zhì).它有時會拋出錯誤,抱怨未找到模型編輯器,尤其是從架子上執(zhí)行時.
另一種方式有點羅嗦,但它每次都有效:
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()
簡單地說,設(shè)置它們,我會使用PyMEL并執(zhí)行:
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
來源:https://www./content-4-352951.html
|