-
Notifications
You must be signed in to change notification settings - Fork 117
ProSnippets Layouts
arcgisprosdk edited this page Mar 27, 2017
·
21 revisions
Language: C#
Subject: Layouts
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: Esri, http://www.esri.com
Date: 1/5/2017
ArcGIS Pro: 1.4
Visual Studio: 2013, 2015
.NET Target Framework: 4.6.1
// get all the layouts
IEnumerable<LayoutProjectItem> layouts = Project.Current.GetItems<LayoutProjectItem>();
// or get a specific layout (by name)
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
// Delete the layout from the project
Project.Current.RemoveAsync(layoutItem);
}
// get the project item
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
// Check for layoutItem
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// get the layout
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// change properties
ArcGIS.Core.CIM.CIMPage page = layout.GetPage();
page.Width = 8.5;
page.Height = 11;
layout.SetPage(page);
layout.SetName("New Name");
}
});
}
// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// find a single specific element
Element rect = layout.FindElement("Rectangle") as Element;
// or use the Elements collection
Element rect2 = layout.Elements.FirstOrDefault(item => item.Name.Equals("Rectangle"));
}
});
}
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// update the name
element.SetName("New Name");
// update visibility
element.SetVisible(true);
});
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// delete a specific element
myLayout.DeleteElement(element);
// or delete a group of elements
myLayout.DeleteElements(item => item.Name.Contains("Clone"));
});
if (element is GroupElement)
{
var grpElement = element as GroupElement;
var grpList = grpElement.Elements;
StringBuilder sb = new StringBuilder();
foreach (Element grpItem in grpList)
sb.AppendLine(grpItem.Name);
}
// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// Reference a text element by name
TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
if (txtElm != null)
{
// Change placement properties
PlacementProperties txtPlacement = txtElm.GetPlacement();
txtPlacement.Anchor = ArcGIS.Core.CIM.Anchor.CenterPoint;
txtPlacement.X = x;
txtPlacement.Y = y;
txtElm.SetPlacement(txtPlacement);
// Change TextProperties
TextProperties txtProperties = new TextProperties("Hello world", "Times New Roman", 48);
txtElm.SetTextProperties(txtProperties);
}
}
});
}
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// Reference a picture element by name
PictureElement picElm = layout.FindElement("MyPicture") as PictureElement;
// Change the path to a new source
if (picElm != null)
picElm.SetSourcePath(@"D:\MyData\Pics\LakeHuron.jpg");
}
});
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// Reference a scale bar element by name
MapSurround scaleBar = layout.FindElement("MyScaleBar") as MapSurround;
// Reference a map frame element by name
MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
if ((scaleBar != null) && (mf != null))
//Set the scale bar to the newly referenced map frame
scaleBar.SetMapFrame(mf);
}
});
// The Locked property is displayed in the TOC as a lock symbol next to each element.
// If locked the element can't be selected in the layout using the graphic
// selection tools.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
//Reference an element by name
Element element = layout.FindElement("MyElement");
if (element != null)
{
// Modify the Locked property via the CIM
ArcGIS.Core.CIM.CIMElement CIMElement = element.Definition as ArcGIS.Core.CIM.CIMElement;
CIMElement.Locked = true;
element.SetDefinition(CIMElement);
}
}
});
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// Reference a element by name
GraphicElement graphicElement = layout.FindElement("MyElement") as GraphicElement;
if (graphicElement != null)
{
// Modify the Transparency property that exists only in the CIMGraphic class.
ArcGIS.Core.CIM.CIMGraphic CIMGraphic = graphicElement.Graphic as ArcGIS.Core.CIM.CIMGraphic;
CIMGraphic.Transparency = 50; // mark it 50% transparent
graphicElement.SetGraphic(CIMGraphic);
}
}
});
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout != null)
{
// Reference a element by name
GraphicElement graphicElement = layout.FindElement("MyElement") as GraphicElement;
if (graphicElement != null)
{
// get the placement properties
PlacementProperties graPlace = graphicElement.GetPlacement();
// clone and set the new x,y
var cloneElement = graphicElement.Clone("Clone");
graPlace.X = graPlace.X + xOffset;
graPlace.Y = graPlace.Y - yOffset;
cloneElement.SetPlacement(graPlace);
}
}
});
// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Reference and load the layout associated with the layout item
Layout layout = layoutItem.GetLayout();
if (layout == null)
return;
// Reference a mapframe by name
MapFrame mf = layout.Elements.FirstOrDefault(item => item.Name.Equals("MapFrame")) as MapFrame;
if (mf == null)
return;
// get the mapframe's MapView
ArcGIS.Desktop.Mapping.MapView mv = mf.MapView;
if (mv == null)
return;
// get the map and the bookmarks
ArcGIS.Desktop.Mapping.Map map = mf.Map;
var bookmarks = map.GetBookmarks();
if (bookmarks == null)
return;
// Loop through each bookmark
foreach (var bookmark in bookmarks)
{
// Set up a PDF format and set its properties
ArcGIS.Desktop.Mapping.PDFFormat PDF = new ArcGIS.Desktop.Mapping.PDFFormat();
String path = String.Format(@"C:\Temp\{0}.pdf", bookmark.Name);
PDF.OutputFileName = path;
// Zoom to the bookmark - use 0 just in case the app backstage Navigation Transition Time is > 0
mv.ZoomTo(bookmark, TimeSpan.FromSeconds(0));
// Export to PDF
if (PDF.ValidateOutputFilePath())
mf.Export(PDF);
}
});
}
// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
Layout layout = layoutItem.GetLayout();
if (layout == null)
return;
// Create BMP format with appropriate settings
ArcGIS.Desktop.Mapping.BMPFormat BMP = new ArcGIS.Desktop.Mapping.BMPFormat();
BMP.Resolution = 300;
BMP.OutputFileName = @"C:\temp\Layout.bmp";
if (BMP.ValidateOutputFilePath())
{
layout.Export(BMP);
}
// Create EMF format with appropriate settings
ArcGIS.Desktop.Mapping.EMFFormat EMF = new ArcGIS.Desktop.Mapping.EMFFormat();
EMF.Resolution = 300;
EMF.OutputFileName = @"C:\temp\Layout.emf";
if (EMF.ValidateOutputFilePath())
{
layout.Export(EMF);
}
// create eps format with appropriate settings
ArcGIS.Desktop.Mapping.EPSFormat EPS = new ArcGIS.Desktop.Mapping.EPSFormat();
EPS.Resolution = 300;
EPS.OutputFileName = @"C:\temp\Layout.eps";
if (EPS.ValidateOutputFilePath())
{
layout.Export(EPS);
}
// Create GIF format with appropriate settings
ArcGIS.Desktop.Mapping.GIFFormat GIF = new ArcGIS.Desktop.Mapping.GIFFormat();
GIF.Resolution = 300;
GIF.OutputFileName = @"C:\temp\Layout.gif";
if (GIF.ValidateOutputFilePath())
{
layout.Export(GIF);
}
// Create JPEG format with appropriate settings
ArcGIS.Desktop.Mapping.JPEGFormat JPEG = new ArcGIS.Desktop.Mapping.JPEGFormat();
JPEG.Resolution = 300;
JPEG.OutputFileName = @"C:\temp\Layout.jpg";
if (JPEG.ValidateOutputFilePath())
{
layout.Export(JPEG);
}
// Create PDF format with appropriate settings
ArcGIS.Desktop.Mapping.PDFFormat PDF = new ArcGIS.Desktop.Mapping.PDFFormat();
PDF.Resolution = 300;
PDF.OutputFileName = @"C:\temp\Layout.pdf";
if (PDF.ValidateOutputFilePath())
{
layout.Export(PDF);
}
// Create PNG format with appropriate settings
ArcGIS.Desktop.Mapping.PNGFormat PNG = new ArcGIS.Desktop.Mapping.PNGFormat();
PNG.Resolution = 300;
PNG.OutputFileName = @"C:\temp\Layout.png";
if (PNG.ValidateOutputFilePath())
{
layout.Export(PNG);
}
// Create SVG format with appropriate settings
ArcGIS.Desktop.Mapping.SVGFormat SVG = new ArcGIS.Desktop.Mapping.SVGFormat();
SVG.Resolution = 300;
SVG.OutputFileName = @"C:\temp\Layout.svg";
if (SVG.ValidateOutputFilePath())
{
layout.Export(SVG);
}
// Create TGA format with appropriate settings
ArcGIS.Desktop.Mapping.TGAFormat TGA = new ArcGIS.Desktop.Mapping.TGAFormat();
TGA.Resolution = 300;
TGA.OutputFileName = @"C:\temp\Layout.tga";
if (TGA.ValidateOutputFilePath())
{
layout.Export(TGA);
}
// Create TIFF format with appropriate settings
ArcGIS.Desktop.Mapping.TIFFFormat TIFF = new ArcGIS.Desktop.Mapping.TIFFFormat();
TIFF.Resolution = 300;
TIFF.OutputFileName = @"C:\temp\Layout.tif";
if (TIFF.ValidateOutputFilePath())
{
layout.Export(TIFF);
}
});
}
// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// get the layout
Layout layout = layoutItem.GetLayout();
if (layout == null)
return;
// get the map frame
MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
if (mf != null)
{
// Create BMP format with appropriate settings
ArcGIS.Desktop.Mapping.BMPFormat BMP = new ArcGIS.Desktop.Mapping.BMPFormat();
BMP.HasWorldFile = true;
BMP.Resolution = 300;
BMP.OutputFileName = @"C:\temp\MapFrame.bmp";
if (BMP.ValidateOutputFilePath())
{
mf.Export(BMP);
}
// emf, eps, gif, jpeg, pdf, png, svg, tga, tiff formats are also available for export
}
});
}
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
if (MapView.Active != null)
{
//Create BMP format with appropriate settings
ArcGIS.Desktop.Mapping.BMPFormat bmp = new ArcGIS.Desktop.Mapping.BMPFormat();
bmp.Resolution = 300;
bmp.Height = 500;
bmp.Width = 800;
bmp.HasWorldFile = true;
bmp.OutputFileName = @"C:\temp\MapView.bmp";
//Export active map view
if (bmp.ValidateOutputFilePath())
{
MapView.Active.Export(bmp);
}
// emf, eps, gif, jpeg, pdf, png, svg, tga, tiff formats also available for export
}
});
Home | API Reference | Requirements | Download | Samples
-
Reference layout project items and their associated layout
-
Open a layout project item in a new view
-
Activate an already open layout view
-
Reference the active layout view
-
Import a pagx into a project
-
Remove a layout project item
-
Create a new, basic layout and open it
-
Create a new layout using a modified CIM and open it
-
Change the layout page size
-
ProSnippet Group CIM Graphics and GraphicFactory
-
Create Circle Graphic
-
Create Circle Text Graphic
-
Create Bezier Graphic
-
Create Legend Patch Graphic
-
Create Arrow Graphic
-
Create Picture Graphic
-
Get Graphic Outline
-
Get Graphic Outline from Graphic Element
-
Create Ellipse Graphic Element
-
Create Lasso Line, Freehand Graphic Element
-
Create Lasso Polygon, Freehand Element
-
Create Line Element
-
Create Point Element
-
Create Polygon Element
-
Create Rectangle Element
-
Create Bezier Curve Element
-
Create Graphic Elements
-
Create Graphic Element using CIMGraphic
-
Create Graphic Element using CIMSymbol
-
Bulk Element creation
-
Create Element using a CIMGraphicElement
-
Create point graphic with symbology
-
Create line graphic with symbology
-
Create rectangle graphic with simple symbology
-
Create Point Text Element 1
-
Create Rectangle Paragraph Text Element 1
-
Create a Dynamic Point Text Element
-
Create Point Text Element 2
-
Create Polygon Paragraph Text Element
-
Create Rectangle Paragraph Text Element 2
-
Create Circle Text Element
-
Create Bezier Text Element
-
Create Ellipse Text Element
-
Create Predefined Shape Graphic Element
-
Create Predefined Shape Graphic Element
-
Create Predefined Shape Graphic Element
-
Create Line Arrow Element
-
Create Picture Graphic Element using CIMSymbol
-
Create a new picture element with advanced symbol settings
-
Create Map Frame and Set Camera
-
Create Legend
-
Create Scale Bar From StyleItem
-
Create North Arrow From StyleItem 1
-
Create Table Frame
-
Create Map Frame 1
-
Create Map Frame 2
-
Create Legend 2
-
Create North Arrow From StyleItem 2
-
Create Table Frame
-
Create Scale Bar
-
Create Scale Line
-
Find an element on a layout
-
Find layout elements
-
Update element properties
-
Get element selection count
-
Set element selection
-
UnSelect elements on the Layout
-
UnSelect elements on the LayoutView
-
Clear the selection in a layout view
-
Clear the selection in a layout
-
Copy Layout Elements
-
Delete Layout Elements
-
Delete an element or elements on a layout
-
Zoom to elements
-
Set halo property of north arrow
-
Group Graphic Elements
-
Un-Group Graphic Elements
-
Parent of GroupElement
-
Children in a Group Element
-
Ordering: Send backward and Bring forward
-
Get Z-Order
-
Update text element properties
-
Update a picture element
-
Apply a Background Color to a MapFrame
-
Update a map surround
-
Lock an element
-
Update an elements transparency
-
Clone an element
-
Apply a style to a North Arrow
-
Apply a style to Grid and Graticules
-
Apply a style to a Graphic Element
-
Change the map associated with a map frame
-
Change map frame camera settings
-
Zoom map frame to extent of a single layer
-
Change map frame extent to selected features in multiple layers
-
Change map frame extent to single feature with 15 percent buffer
-
Activate Map Frame
-
Deactivate Map Frame
-
Get the Activated Map Frame and MapView
-
Translates a point in page coordinates to a point in map coordinates.
-
Translates a point in map coordinates to a point in page coordinates
-
Export a layout to PDF
-
Export a map frame to JPG
-
Export the map view associated with a map frame to BMP
-
Export a map series to single PDF
-
Export a map series to individual TIFF files
-
SetAutoCameraNone
-
SetAutoCameraFixedExtent
-
SetAutoCameraFixedCenter
-
SetAutoCameraFixedCenterAndScale
-
SetAutoCameraFixedScale
-
SetAutoCameraLinkedExtent
-
SetAutoCameraLinkedCenter
-
SetAutoCameraLinkedCenterAndScale
-
SetAutoCameraLinkedScale
-
SetAutoCameraLinkedMapSeriesShape
-
SetAutoCameraLinkedMapSeriesCenter