ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / ValidateAutoCamera Method
The auto camera to validate
Example Version

ValidateAutoCamera Method
Validates the input CIMAutoCamera for the given ArcGIS.Core.CIM.CIMAutoCamera.Source and ArcGIS.Core.CIM.CIMAutoCamera.AutoCameraType values. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public bool ValidateAutoCamera( 
   CIMAutoCamera autoCamera
)

Parameters

autoCamera
The auto camera to validate

Return Value

True if the autocamera is valid for this mapframe.
Exceptions
ExceptionDescription
This method or property must be called within the lambda passed to QueuedTask.Run.
Remarks
An auto camera is used to set map frame display constraints. Display constraints are used to set limits on the map extent within the map frame. Refer to Map frame constraints in the Pro product help for more information on constraints. Only required settings for the given AutoCameraSource will be validated. Optional, or "non-required", settings are ignored (eg autoCamera.Margin). Validation criteria differ depending on the ArcGIS.Core.CIM.CIMAutoCamera.Source and ArcGIS.Core.CIM.CIMAutoCamera.AutoCameraType values. The criteria are as follows:
o ArcGIS.Core.CIM.AutoCameraSource.None: there are no required settings. An autocamera with source value AutoCameraSource.None is always considered valid.
o ArcGIS.Core.CIM.AutoCameraSource.Fixed: autoCamera.AutoCameraType is evaluated as follows:
o ArcGIS.Core.CIM.AutoCameraType.Extent: ArcGIS.Core.CIM.CIMAutoCamera.Extent must be present. If ArcGIS.Core.CIM.CIMAutoCamera.IntersectLayerPath is specified it must be the URI of a valid layer in the mapframe's map.
o ArcGIS.Core.CIM.AutoCameraType.Center: ArcGIS.Core.CIM.CIMAutoCamera.Camera must be present. If ArcGIS.Core.CIM.CIMAutoCamera.IntersectLayerPath is specified it must be the URI of a valid layer in the mapframe's map.
o ArcGIS.Core.CIM.AutoCameraType.CenterAndScale: ArcGIS.Core.CIM.CIMAutoCamera.Camera must be present.
o ArcGIS.Core.CIM.AutoCameraType.Scale: ArcGIS.Core.CIM.CIMAutoCamera.Camera must be present.
Note: the X,Y of the camera, when present, must fall within the domain of the mapframe's map spatial reference. o ArcGIS.Core.CIM.AutoCameraSource.MapFrameLink: autoCamera.AutoCameraType is evaluated as follows:
o ArcGIS.Core.CIM.AutoCameraType.Extent:
o ArcGIS.Core.CIM.AutoCameraType.Center:
ArcGIS.Core.CIM.CIMAutoCamera.MapFrameLinkName must be present and point to a valid map frame in the same layout other than itself. If ArcGIS.Core.CIM.CIMAutoCamera.IntersectLayerPath is specified it must be the URI of a valid layer in the mapframe's map.
o ArcGIS.Core.CIM.AutoCameraType.CenterAndScale:
o ArcGIS.Core.CIM.AutoCameraType.Scale:
ArcGIS.Core.CIM.CIMAutoCamera.MapFrameLinkName must be present and point to a valid map frame in the same layout other than itself
o ArcGIS.Core.CIM.AutoCameraSource.MapSeriesLink A map series must be present in the layout. It can be enabled or disabled. autoCamera.AutoCameraType is evaluated as follows:
o ArcGIS.Core.CIM.AutoCameraType.Extent:
o ArcGIS.Core.CIM.AutoCameraType.Center:
If ArcGIS.Core.CIM.CIMAutoCamera.IntersectLayerPath is specified it must be the URI of a valid layer in the mapframe's map.
Note:Extent and Camera properties are ignored.
o ArcGIS.Core.CIM.AutoCameraType.CenterAndScale: invalid autoCamera.AutoCameraType.
o ArcGIS.Core.CIM.AutoCameraType.Scale: invalid autoCamera.AutoCameraType.
Example
SetAutoCameraNone
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.None;
if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedExtent
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Extent;

var mf_extent = mf.GetViewExtent();

var extent = EnvelopeBuilderEx.CreateEnvelope(
  400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
autoCamera.Extent = extent;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedCenter
//Note: run within the QueuedTask
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Center;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 21169571,
  X = 855708,
  Y = 1112409,
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedCenterAndScale
//Note: run within the QueuedTask
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.CenterAndScale;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 21169571,
  X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
  Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;


if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraFixedScale
//Note: run within the QueuedTask
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Scale;

var camera = mf.GetMapView(LayoutView.Active).Camera;
var center = mf.GetViewCenter();

//var extent = EnvelopeBuilderEx.CreateEnvelope(
//    400748.62, 800296.4, 1310669.05, 1424520.74, mf.Map.SpatialReference);
//autoCamera.Extent = extent;

var camera2 = new CIMViewCamera()
{
  Heading = 0,
  Pitch = -90,
  Roll = 0,
  Scale = 20000571,
  X = 1310669.0 + ((400748.5 - 1310669.0) / 2.0),
  Y = 800296.4 + ((1424520.74 - 800296.4) / 2.0),
  Z = double.NaN
};
autoCamera.Camera = camera2;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedExtent
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapFrameLink;
autoCamera.AutoCameraType = AutoCameraType.Extent;
autoCamera.MapFrameLinkName = mapFrameLink;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedCenter
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapFrameLink;
autoCamera.AutoCameraType = AutoCameraType.Center;
autoCamera.MapFrameLinkName = mapFrameLink;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedCenterAndScale
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapFrameLink;
autoCamera.AutoCameraType = AutoCameraType.CenterAndScale;
autoCamera.MapFrameLinkName = mapFrameLink;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedScale
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapFrameLink;
autoCamera.AutoCameraType = AutoCameraType.Scale;
autoCamera.MapFrameLinkName = mapFrameLink;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedMapSeriesShape
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapSeriesLink;
autoCamera.AutoCameraType = AutoCameraType.Extent;
//autoCamera.MapFrameLinkName = mapFrameLink;
var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
SetAutoCameraLinkedMapSeriesCenter
var layout = LayoutView.Active.Layout;
var mf = layout.GetElementsAsFlattenedList().OfType<MapFrame>()
  .First(mf => mf.Name == mapFrame);
var autoCamera = mf.GetAutoCamera();
autoCamera.Source = AutoCameraSource.MapSeriesLink;
autoCamera.AutoCameraType = AutoCameraType.Center;

var states = mf.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;

if (mf.ValidateAutoCamera(autoCamera) &&
  !mf.IsMapSeriesMapFrame())
  mf.SetAutoCamera(autoCamera);
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also