guys. What I'm trying to do is searching all user created cameras in the scene and change attributes of them at the same time. This is what I got so far and this changes only one camera's attribute. Can I get some advice? I guess I need to know how to make a list of this defined user created cameras so that I can change all of them at the same time.
Thank you in advance.
import maya.cmds as cmds
allCams = cmds.ls(type=('camera'), l=True)
dfCams = [camera for camera in cameras if cmds.camera(cmds.listRelatives(camera, parent=True)[0],startupCamera=True, q=True)]
myCams = list(set(allCams) - set(dfCams))
cmds.setAttr((myCams[0] + '.nearClipPlane'), 0.01)
cmds.setAttr((myCams[0] + '.farClipPlane'), 1000000)
a simple loop should do the trick, here is an example with dictionnary but you could zip your attrs/values into a list too
import maya.cmds as cmds
allCams = cmds.ls(type='camera')
defCam = ['perspShape','topShape', 'sideShape', 'frontShape']
cams = list(set(allCams)-set(defCam))
attributes = {'nearClipPlane':0.01,
'farClipPlane':1000000}
for c in cams:
for attrName in attributes.keys():
cmds.setAttr('{}.{}'.format(c, attrName), attributes[attrName])
Also, note that in your code :
allCams = cmds.ls(type=('camera'), l=True)
will give long names against your listRelatives :
cmds.listRelatives(camera, parent=True)
that need the flag -fullPath to return long path
You wont be able to susbstract your sets otherwise. I would recommend to do :
defaultcam = [i for i in allCams if cmds.camera(i, startupCamera=True, q=True)]
fullDefCam = cmds.ls(defaultcam, l=True)