ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Element Class / GetBounds Method
True to retrieve the rotated bounds
Example

In This Topic
    GetBounds Method (Element)
    In This Topic
    Gets the bounding box for the element. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public Envelope GetBounds( 
       bool rotated
    )
    Public Function GetBounds( _
       Optional ByVal rotated As Boolean _
    ) As Envelope

    Parameters

    rotated
    True to retrieve the rotated bounds

    Return Value

    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Remarks
    Bounds always reflect the element extent in a non-rotated orientation. If element rotation is non-zero, use graphicBounds = true to return the minimum bounding box enclosing the element in its rotated position
    Example
    Translates a point in page coordinates to a point in map coordinates.
    //On the QueuedTask
    var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
    var mapFrame = layout.FindElement("New Map Frame") as MapFrame;
    
    //Get a point in the center of the Map frame
    var mapFrameCenterPoint = mapFrame.GetBounds().CenterCoordinate;
    //Convert to MapPoint
    //At 2.x - var pointInMapFrame = MapPointBuilder.CreateMapPoint(mapFrameCenterPoint);
    var pointInMapFrame = MapPointBuilderEx.CreateMapPoint(mapFrameCenterPoint);
    
    //Find the corresponding point in the MapView
    var pointOnMap = mapFrame.PageToMap(pointInMapFrame);
    
    //Create a point graphic on the MapView.
    var cimGraphicElement = new CIMPointGraphic
    {
      Location = pointOnMap,
      Symbol = pointSymbol.MakeSymbolReference()
    };
    graphicsLayer.AddElement(cimGraphicElement);
    Zoom to specific location on Report view
    //On the QueuedTask
    var detailsSection = report.Elements.OfType<ReportSection>().FirstOrDefault().Elements.OfType<ReportDetails>().FirstOrDefault();
    var bounds = detailsSection.GetBounds();
    ReportView.Active.ZoomTo(bounds);
    Create a new field in the report
    //This is the gap between two fields
    double fieldIncrement = 0.9388875113593206276389;
    //On the QueuedTask
    //New field to add.
    var newReportField = new CIMReportField
    {
      Name = "POP1990",
      FieldOrder = 2,
    };
    //Get the "ReportSection element"                
    var mainReportSection = report.Elements.OfType<ReportSection>().FirstOrDefault();
    if (mainReportSection == null) return;
    
    //Get the "ReportDetails" within the ReportSectionElement. ReportDetails is where "fields" are.
    var reportDetailsSection = mainReportSection?.Elements.OfType<ReportDetails>().FirstOrDefault();
    if (reportDetailsSection == null) return;
    
    //Within ReportDetails find the envelope that encloses a field.
    //We get the first CIMParagraphTextGraphic in the collection so that we can add the new field next to it.                    
    var lastFieldGraphic = reportDetailsSection.Elements.FirstOrDefault((r) =>
    {
      var gr = r as GraphicElement;
      if (gr == null) return false;
      return (gr.GetGraphic() is CIMParagraphTextGraphic ? true : false);
    });
    //Get the Envelope of the last field
    var graphicBounds = lastFieldGraphic.GetBounds();
    
    //Min and Max values of the envelope
    var xMinOfFieldEnvelope = graphicBounds.XMin;
    var yMinOfFieldEnvelope = graphicBounds.YMin;
    
    var xMaxOfFieldEnvelope = graphicBounds.XMax;
    var YMaxOfFieldEnvelope = graphicBounds.YMax;
    //create the new Envelope to be offset from the existing field
    //At 2.x
    //MapPoint newMinPoint = MapPointBuilder.CreateMapPoint(xMinOfFieldEnvelope + fieldIncrement, yMinOfFieldEnvelope);
    //MapPoint newMaxPoint = MapPointBuilder.CreateMapPoint(xMaxOfFieldEnvelope + fieldIncrement, YMaxOfFieldEnvelope);
    //Envelope newFieldEnvelope = EnvelopeBuilder.CreateEnvelope(newMinPoint, newMaxPoint);
    
    MapPoint newMinPoint = MapPointBuilderEx.CreateMapPoint(xMinOfFieldEnvelope + fieldIncrement, yMinOfFieldEnvelope);
    MapPoint newMaxPoint = MapPointBuilderEx.CreateMapPoint(xMaxOfFieldEnvelope + fieldIncrement, YMaxOfFieldEnvelope);
    Envelope newFieldEnvelope = EnvelopeBuilderEx.CreateEnvelope(newMinPoint, newMaxPoint);
    
    //Create field
    GraphicElement fieldGraphic = ReportElementFactory.Instance.CreateFieldValueTextElement(reportDetailsSection, newFieldEnvelope, newReportField);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also