Parameters
- x
- Double
| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method must be called within the lambda passed to QueuedTask.Run. |
| System.InvalidOperationException | This element requires its mapview to be active |
{
//Create a simple point text element and assign basic symbology and text settings.
//Note: Must be on QueuedTask.Run
//Build 2D point geometry
Coordinate2D coord2D = new Coordinate2D(3.5, 10);
//Set symbology, create and add element to layout
CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
string textString = "Point text";
//use ElementInfo to set placement properties during create
var elemInfo = new ElementInfo()
{
Anchor = Anchor.CenterPoint,
Rotation = 45
};
var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
layout, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
"New Point Text", true, elemInfo);
//Change additional text properties
ptTxtElm.SetX(4.5);
ptTxtElm.SetY(9.5);
}
{
//Note: Must be on QueuedTask.Run
//Build geometry
Coordinate2D center = new Coordinate2D(7, 5.5);
//Reference a North Arrow in a style
StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
.FirstOrDefault(item => item.Name == "ArcGIS 2D");
NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows(
"ArcGIS North 10")[0];
//Reference MF, create north arrow and add to layout
var mf = layout.FindElement("Map Frame") as MapFrame;
var narrow_info = new NorthArrowInfo()
{
MapFrameName = mf.Name,
NorthArrowStyleItem = naStyleItm
};
var arrowElm = (NorthArrow)ElementFactory.Instance.CreateMapSurroundElement(
layout, center.ToMapPoint(), narrow_info) as NorthArrow;
arrowElm.SetName("New North Arrow");
arrowElm.SetHeight(1.75);
arrowElm.SetX(7);
arrowElm.SetY(6);
}
{
//Update text element properties for an existing text element.
//Note: Must be on QueuedTask.Run
// Reference and load the layout associated with the layout item
if (layout != null)
{
// Reference a text element by name
TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
if (txtElm != null)
{
double x = 2.0;
double y = 3.0;
// Change placement properties
txtElm.SetAnchor(Anchor.CenterPoint);
txtElm.SetX(x);
txtElm.SetY(y);
// Change TextProperties
TextProperties txtProperties = new TextProperties(
"Hello world", "Times New Roman", 48, "Regular");
txtElm.SetTextProperties(txtProperties);
}
}
{
//Clone a layout graphic element and apply an offset.
//Note: Must be on QueuedTask.Run
// Reference a graphic element by name
GraphicElement graphicElement =
layout.FindElement("MyElement") as GraphicElement;
if (graphicElement != null)
{
//Clone and set the new x,y
GraphicElement cloneElement = graphicElement.Clone("Clone");
double xOffset = 0;
double yOffset = 0;
cloneElement.SetX(cloneElement.GetX() + xOffset);
cloneElement.SetY(cloneElement.GetY() + yOffset);
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)