Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Created November 2, 2018 09:26
Show Gist options
  • Save paulwinex/785aaffcdcd5998ed07e2ac69889e72e to your computer and use it in GitHub Desktop.
Save paulwinex/785aaffcdcd5998ed07e2ac69889e72e to your computer and use it in GitHub Desktop.
import pymel.core.uitypes as pmui
model_panel = pmui.ModelEditor(pm.getPanel(withFocus=True))
print pmui.ModelEditor.getRendererName(model_panel)
# Although, that snippet seems to be temperamental. It sometimes throws an error complaining that the model editor was not found, especially when executed from the shelf.
# Another way would be a bit wordy, but it works everytime:
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
# A concise, pseudo-PyMEL way would be to just PyMEL-ify Tomek's answer:
import pymel.core as pm
print pm.modelEditor(pm.getPanel(wf=True), q=True, rnm=True)
To get a list of viewport renderers:
import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererList()
# Here is some extra info on model editors and viewport renderers. To get their "friendly" names:
import pymel.core.uitypes as pmui
print pmui.ModelEditor().getRendererListUI()
# To set them, concisely, I would use PyMEL and do:
import pymel.core.uitypes as pmui
# assuming you know which modelPanel you want to affect
pmui.ModelEditor("modelPanel4").setRendererName("ogsRenderer")
# To affect all viewports (modelPanels) I would do:
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")
# To affect just the viewport in focus:
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment