To automatically calculate distance between a camera and target locator.
- Create > Measure Tools > distance Tool. Select center of camera and where the target locator will be
- Since render with Arnold, it need to connect to CameraShape1 + Arnold Focus Distance. NOTE: It’s Not Maya default [Depth of Field > Focus Distance]
- MEL Command line is
connectAttr -f distanceDimension1.distance cameraShape1.aiFocusDistance;
Now as you move either the target or camera, automatically calculate the focus distance for DOF! Just adjust Aperture Size.

