pythonmayapymel

How to get Stereoscopic Camera Lens Lengths attribute via Python?


I have a Python script that stores the attributes of a stereoscopic camera into a json file and I am having trouble storing the lens Lengths attribute. I am new to Maya and this might be a very obvious thing to ask so I appreciate any input.

This is what I have tried so far:

import maya.cmds as cmds 

print(cmds.getAttr("cameraMain_C0_ctl.lensLengths"))

I was expecting to see a value of 15 or 15mm but I get zero.

a screenshot of the attribute I am trying to store

Is it possible to store this value?

Thanks.


Solution

  • Use the following code to get the attributes (camera shapes):

    import maya.cmds as cmds 
    
    focalLengthCenter = cmds.camera("stereoCameraCenterCamShape", q=True, fl=True)
    focalLengthLeft = cmds.camera("stereoCameraLeft", q=True, fl=True)
    focalLengthRight = cmds.camera("stereoCameraRight", q=True, fl=True)
    
    print(focalLengthCenter, focalLengthLeft, focalLengthRight)
    
    # Result (70.0, 70.0, 70.0)
    

    enter image description here