public static LayoutView Active {get;}
Public Shared ReadOnly Property Active As LayoutView
public static LayoutView Active {get;}
Public Shared ReadOnly Property Active As LayoutView
{
//Reference the active layout view.
//Confirm if the current, active view is a layout view.
//If it is, do something.
LayoutView activeLayoutView = LayoutView.Active;
if (activeLayoutView != null)
{
// do something
}
}
{
//Get element's selection count.
//Count the number of selected elements on the active layout view
LayoutView activeLayoutView = LayoutView.Active;
if (activeLayoutView != null)
{
var selectedElements = activeLayoutView.GetSelectedElements();
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($@"Selected elements: {selectedElements.Count}");
}
}
{
//Set the active layout view's selection to include 2 rectangle elements.
//Reference the active view
LayoutView activeLayoutView = LayoutView.Active;
if (activeLayoutView != null)
{
await QueuedTask.Run(() =>
{
//Reference the layout
Layout lyt = activeLayoutView.Layout;
//Reference the two rectangle elements
Element rec = lyt.FindElement("Rectangle");
Element rec2 = lyt.FindElement("Rectangle 2");
//Construct a list and add the elements
List<Element> elmList = new List<Element>
{
rec,
rec2
};
//Set the selection
activeLayoutView.SelectElements(elmList);
});
}
}
{
//If the a layout view is active, clear its selection
LayoutView activeLayoutView = LayoutView.Active;
activeLayoutView?.ClearElementSelection();
}
{
LayoutView lytView = LayoutView.Active;
//Zoom to an element
var elementToZoomTo = layout.FindElements(new List<string>() { "MyPoint" }).FirstOrDefault();
lytView.ZoomToElement(elementToZoomTo);
//Zoom to multiple elements.
var elementsToZoomTo = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
lytView.ZoomToElements(elementsToZoomTo);
}
{
//Set the CIM halo properties of a north arrow.
//Reference the first selected north arrow element
var northArrow = LayoutView.Active.GetSelectedElements().OfType<NorthArrow>().First();
await QueuedTask.Run(() =>
{
//Get definition of north arrow...
var cim = northArrow.GetDefinition() as CIMMarkerNorthArrow;
//this halo symbol is 50% transparent, no outline (i.e. 0 width)
//First construct a polygon symbol to use in the Halo
//Polygon symbol will need a fill and a stroke
var polyFill = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.CreateRGBColor(0, 0, 0, 50));
var polyStroke = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 0);
var haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(polyFill, polyStroke);
//Set the north arrow definition of HaloSymbol and HaloSize
((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSymbol = haloPoly;
((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSize = 3;//size of the halo
//Apply the CIM changes back to the element
northArrow.SetDefinition(cim);
});
}
{
//The active view must be a layout view.
var lv = LayoutView.Active;
if (lv == null)
{
return;
}
var map_view = lv.ActivatedMapView;
if (map_view != null)
{
//TODO - use activated map view
}
var map_frame = lv.ActivatedMapFrame;
if (map_frame != null)
{
//TODO - use activated map frame
}
}
{
var activeLayoutView = LayoutView.Active;
await QueuedTask.Run(() =>
{
var autoCamera = mapFrame.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Center;
var camera = mapFrame.GetMapView(activeLayoutView).Camera;
var center = mapFrame.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 = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
autoCamera.IntersectLayerPath = states.URI;
if (mapFrame.ValidateAutoCamera(autoCamera) &&
!mapFrame.IsMapSeriesMapFrame())
{
mapFrame.SetAutoCamera(autoCamera);
}
});
}
{
var activeLayoutView = LayoutView.Active;
await QueuedTask.Run(() =>
{
var autoCamera = mapFrame.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.CenterAndScale;
var camera = mapFrame.GetMapView(activeLayoutView).Camera;
var center = mapFrame.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 = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;
if (mapFrame.ValidateAutoCamera(autoCamera) &&
!mapFrame.IsMapSeriesMapFrame())
{
mapFrame.SetAutoCamera(autoCamera);
}
});
}
{
var activeLayoutView = LayoutView.Active;
await QueuedTask.Run(() =>
{
var autoCamera = mapFrame.GetAutoCamera();
autoCamera.Source = AutoCameraSource.Fixed;
autoCamera.AutoCameraType = AutoCameraType.Scale;
var camera = mapFrame.GetMapView(activeLayoutView).Camera;
var center = mapFrame.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 = mapFrame.Map.GetLayersAsFlattenedList().First(l => l.Name == "State_Polygons");
//autoCamera.IntersectLayerPath = states.URI;
if (mapFrame.ValidateAutoCamera(autoCamera) &&
!mapFrame.IsMapSeriesMapFrame())
{
mapFrame.SetAutoCamera(autoCamera);
}
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)