Skip to content

Instantly share code, notes, and snippets.

@ladyponsonia
Last active August 29, 2015 14:27
create camera from viewport
import maya.cmds as mc
#find current cam
currentPan = None
currentPan = mc.getPanel(wf=True)
#check viewport is selected
exists = mc.modelPanel(currentPan, ex=True)
def createCam():
if exists:
#find current cam
cam = mc.modelPanel(currentPan, q=True, camera=True)
else:
mc.confirmDialog(title='Warning', message='Please select viewport', button='ok')
return
newCam = mc.duplicate(cam, name= 'cam0#')
#show resolution gate
mc.camera( newCam, e=True, dr=True )
mc.setAttr(str(newCam[0])+'.visibility',1, e=True)
#open in another window
window = mc.window(widthHeight=(800, 800))
mc.paneLayout()
pan = mc.modelPanel()
# display smooth shaded, no nurb curves
mc.modelEditor(pan, e=True, da="smoothShaded", nc=False, gr=False)
mc.lookThru(pan, newCam)
mc.showWindow( window )
createCam()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment