async public static void LayoutViewClassSnippets() { LayoutView layoutView = LayoutView.Active; await QueuedTask.Run(() => { #region LayoutView_ZoomTo //Note: call within QueuedTask.Run() var lytExt = layoutView.Extent; layoutView.ZoomTo(lytExt); #endregion LayoutView_ZoomTo #region LayoutView_ZoomTo100Percent //Note: call within QueuedTask.Run() layoutView.ZoomTo100Percent(); #endregion LayoutView_Zoom100percent #region LayoutView_ZoomToNext //Note: call within QueuedTask.Run() layoutView.ZoomToNext(); #endregion LayoutView_ZoomToNext #region LayoutView_ZoomToPageWidth //Note: call within QueuedTask.Run() layoutView.ZoomToPageWidth(); #endregion LayoutView_ZoomToPageWidth #region LayoutView_ZoomToPrevious //Note: call within QueuedTask.Run() layoutView.ZoomToPrevious(); #endregion LayoutView_ZoomToPrevious #region LayoutView_ZoomToSelectedElements //Note: call within QueuedTask.Run() layoutView.ZoomToSelectedElements(); #endregion LayoutView_ZoomToSelectedElements #region LayoutView_ZoomToWholePage //Note: call within QueuedTask.Run() layoutView.ZoomToWholePage(); #endregion LayoutView_ZoomToWholePage }); #region LayoutView_GetSelection var selectedElements = layoutView.GetSelectedElements(); #endregion #region LayoutView_SetSelection Element rec = layoutView.Layout.FindElement("Rectangle"); Element rec2 = layoutView.Layout.FindElement("Rectangle 2"); List <Element> elmList = new List <Element>(); elmList.Add(rec); elmList.Add(rec2); layoutView.SelectElements(elmList); #endregion LayoutView_SetSelection #region LayoutView_SelectAll layoutView.SelectAllElements(); #endregion LayoutView_SelectAll #region LayoutView_ClearSelection layoutView.ClearElementSelection(); #endregion LayoutView_ClearSelection Layout layout = LayoutFactory.Instance.CreateLayout(5, 5, LinearUnit.Inches); #region LayoutView_CreateLayoutPane2 await ProApp.Panes.CreateLayoutPaneAsync(layoutView.Layout); #endregion LayoutView_CreateLayoutPane2 #region LayoutView_FindLayoutPanes var panes = ProApp.Panes.FindLayoutPanes(layout); #endregion LayoutView_FindLayoutPanes #region LayoutView_CloseLayoutPanes ProApp.Panes.CloseLayoutPanes(layout.URI); #endregion LayoutView_CloseLayoutPanes #region LayoutView_LayoutFrameWorkExtender //This sample checks to see if a layout project item already has an open application pane. //If it does, it makes sure it is active layout view, if not, it creates, activates and opens a new pane. //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout View")); //Get the layout associated with the layoutitem Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout()); //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { var layoutPane = pane as ILayoutPane; if (layoutPane == null) //if not a layout pane, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == lyt) //if the layout pane does match the layout, activate it. { (layoutPane as Pane).Activate(); layoutPane.Caption = "This is a test"; System.Windows.MessageBox.Show(layoutPane.Caption); return; } } //Otherwise, create, open, and activate the layout if not already open await ProApp.Panes.CreateLayoutPaneAsync(lyt); #endregion LayoutView_LayoutFrameWorkExtender }
public void snippets_elements() { #region Find an element on a layout // Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout")); if (layoutItem != null) { 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")); } }); } #endregion Element element = null; #region Update element properties QueuedTask.Run(() => { // update an element's name element.SetName("New Name"); // update and element's visibility element.SetVisible(true); }); #endregion { #region Get element 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}"); } #endregion } { #region Set element selection //The the active layout view's selection to include 2 rectangle elements LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { QueuedTask.Run(() => { Layout lyt = activeLayoutView.Layout; Element rec = lyt.FindElement("Rectangle"); Element rec2 = lyt.FindElement("Rectangle 2"); List <Element> elmList = new List <Element> { rec, rec2 }; activeLayoutView.SelectElements(elmList); }); } #endregion } { #region Clear the layout selection //If the a layout view is active, the clear its selection LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { activeLayoutView.ClearElementSelection(); } #endregion } Layout aLayout = null; Element elm = null; #region Delete an element or elements on a layout QueuedTask.Run(() => { //Delete a specific element on a layout aLayout.DeleteElement(elm); //Or delete a group of elements using a filter aLayout.DeleteElements(item => item.Name.Contains("Clone")); //Or delete all elements on a layout aLayout.DeleteElements(item => true); }); #endregion #region Set Halo property of North Arrow //Assuming the selected item is a north arrow var northArrow = LayoutView.Active.GetSelectedElements().First(); 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 defintion of HaloSymbol and HaloSize ((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSymbol = haloPoly; ((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSize = 3; //size of the halo //set it back northArrow.SetDefinition(cim); }); #endregion }
async public static void MethodSnippets() { LayoutView layoutView = LayoutView.Active; #region LayoutView_ZoomTo_Extent //Set the page extent for a layout view. //Process on worker thread await QueuedTask.Run(() => { var lytExt = layoutView.Extent; layoutView.ZoomTo(lytExt); }); #endregion LayoutView_ZoomTo_Extent #region LayoutView_ZoomTo_Percent //Set the layout view to 100 percent. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomTo100Percent(); }); #endregion LayoutView_ZoomTo_Percent #region LayoutView_ZoomTo_Next //Advance the layout view extent to the previous forward extent //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToNext(); }); #endregion LayoutView_ZoomTo_Next #region LayoutView_ZoomTo_PageWidth //Set the layout view extent to accomodate the width of the page. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToPageWidth(); }); #endregion LayoutView_ZoomTo_PageWidth #region LayoutView_ZoomTo_Previous //Set the layout view extent to the previous extent. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToPrevious(); }); #endregion LayoutView_ZoomTo_Previous #region LayoutView_ZoomTo_SelectedElements //Set the layout view extent to the selected elements. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToSelectedElements(); }); #endregion LayoutView_ZoomTo_SelectedElements #region LayoutView_ZoomTo_WholePage //Set the layout view extent to fit the entire page. //Process on worker thread await QueuedTask.Run(() => { layoutView.ZoomToWholePage(); }); #endregion LayoutView_ZoomTo_WholePage #region LayoutView_Refresh //Refresh the layout view. //Process on worker thread await QueuedTask.Run(() => layoutView.Refresh()); #endregion #region LayoutView_GetSelection //Get the selected layout elements. var selectedElements = layoutView.GetSelectedElements(); #endregion #region LayoutView_SetSelection //Set the layout's element selection. Element rec = layoutView.Layout.FindElement("Rectangle"); Element rec2 = layoutView.Layout.FindElement("Rectangle 2"); List <Element> elmList = new List <Element>(); elmList.Add(rec); elmList.Add(rec2); layoutView.SelectElements(elmList); #endregion LayoutView_SetSelection #region LayoutView_SelectAll //Select all element on a layout. layoutView.SelectAllElements(); #endregion LayoutView_SelectAll #region LayoutView_ClearSelection //Clear the layout's element selection. layoutView.ClearElementSelection(); #endregion LayoutView_ClearSelection Layout layout = LayoutFactory.Instance.CreateLayout(5, 5, LinearUnit.Inches); #region LayoutView_FindAndCloseLayoutPanes //Find and close all layout panes associated with a specific layout. LayoutProjectItem findLytItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout")); Layout findLyt = await QueuedTask.Run(() => findLytItem.GetLayout()); //Perform on the worker thread var panes = ProApp.Panes.FindLayoutPanes(findLyt); foreach (Pane pane in panes) { ProApp.Panes.CloseLayoutPanes(findLyt.URI); //Close the pane } #endregion LayoutView_FindandCloseLayoutPanes #region LayoutView_LayoutFrameWorkExtender //This sample checks to see if a layout project item already has an open application pane. //If it does, it checks if it is the active layout view, if not, it creates, activates and opens a new pane. //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout View")); //Get the layout associated with the layoutitem Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout()); //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { var layoutPane = pane as ILayoutPane; if (layoutPane == null) //if not a layout pane, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == lyt) //if the layout pane does match the layout, activate it. { (layoutPane as Pane).Activate(); layoutPane.Caption = "This is a test"; System.Windows.MessageBox.Show(layoutPane.Caption); return; } } //Otherwise, create, open, and activate the layout if not already open ILayoutPane newPane = await ProApp.Panes.CreateLayoutPaneAsync(lyt); //Zoom to the full extent of the layout await QueuedTask.Run(() => newPane.LayoutView.ZoomTo100Percent()); #endregion LayoutView_LayoutFrameWorkExtender }