async protected override void OnClick() { LayoutView layoutView = LayoutView.Active; //Prevent tool from executing based on some conditions if (layoutView == null) { System.Windows.MessageBox.Show("Can't find layout view, try clicking New Game Board"); return; } if (layoutView.Layout.Name != "Game Board") { System.Windows.MessageBox.Show("Wrong layout view: should be Game Board"); return; } await QueuedTask.Run(() => { //Reference the layout for moving map frames and adding new layout elements Layout layout = layoutView.Layout; //Check to see if elements were already scrambled MapFrame mfTest = layout.FindElement("MF1") as MapFrame; if (mfTest != null) { System.Windows.MessageBox.Show("Game pieces already scrambled"); return; } //Build 6 envelopes to represent the locations of puzzle pieces along the outer edges Coordinate2D env1_ll = new Coordinate2D(0.5, 0.5); Coordinate2D env1_ur = new Coordinate2D(3.5, 3.5); Envelope env1 = EnvelopeBuilder.CreateEnvelope(env1_ll, env1_ur); Coordinate2D env2_ll = new Coordinate2D(0.5, 4); Coordinate2D env2_ur = new Coordinate2D(3.5, 7); Envelope env2 = EnvelopeBuilder.CreateEnvelope(env2_ll, env2_ur); Coordinate2D env3_ll = new Coordinate2D(0.5, 7.5); Coordinate2D env3_ur = new Coordinate2D(3.5, 10.5); Envelope env3 = EnvelopeBuilder.CreateEnvelope(env3_ll, env3_ur); Coordinate2D env4_ll = new Coordinate2D(13.5, 0.5); Coordinate2D env4_ur = new Coordinate2D(16.5, 3.5); Envelope env4 = EnvelopeBuilder.CreateEnvelope(env4_ll, env4_ur); Coordinate2D env5_ll = new Coordinate2D(13.5, 4); Coordinate2D env5_ur = new Coordinate2D(16.5, 7); Envelope env5 = EnvelopeBuilder.CreateEnvelope(env5_ll, env5_ur); Coordinate2D env6_ll = new Coordinate2D(13.5, 7.5); Coordinate2D env6_ur = new Coordinate2D(16.5, 10.5); Envelope env6 = EnvelopeBuilder.CreateEnvelope(env6_ll, env6_ur); //Randomize the envelopes by assigning new envelope variables used for map frame creation //Also remove the assigned env before selecting the next random env List <Envelope> envList = new List <Envelope> { env1, env2, env3, env4, env5, env6 }; Random r1 = new Random(); int i1 = r1.Next(envList.Count); Envelope e1 = envList[i1]; envList.Remove(e1); Random r2 = new Random(); int i2 = r2.Next(envList.Count); Envelope e2 = envList[i2]; envList.Remove(e2); Random r3 = new Random(); int i3 = r3.Next(envList.Count); Envelope e3 = envList[i3]; envList.Remove(e3); Random r4 = new Random(); int i4 = r4.Next(envList.Count); Envelope e4 = envList[i4]; envList.Remove(e4); Random r5 = new Random(); int i5 = r5.Next(envList.Count); Envelope e5 = envList[i5]; envList.Remove(e5); Random r6 = new Random(); int i6 = r6.Next(envList.Count); Envelope e6 = envList[i6]; envList.Remove(e6); //Reference the active map view and gets its center location //MapView map = MapView.Active; MapFrame mapFrame = layout.FindElement("Main MF") as MapFrame; Camera cam = mapFrame.Camera; double x = cam.X; double y = cam.Y; double scale = cam.Scale; double delta = scale * 1.5 / 12 / 3.28084; //scale * 1/2 of a 3" MF / 12" per foot / 3.28084 feet per meter //Insert Map Frame 1 at random location MapFrame mf1Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e1, mapFrame.Map); mf1Elm.SetName("MF1"); Camera mf1cam = mf1Elm.Camera; mf1cam.X = x - (delta * 2); mf1cam.Y = y - delta; mf1cam.Scale = scale; mf1Elm.SetCamera(mf1cam); //Insert Map Frame 2 at random location MapFrame mf2Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e2, mapFrame.Map); mf2Elm.SetName("MF2"); Camera mf2cam = mf2Elm.Camera; mf2cam.X = x; mf2cam.Y = y - delta; mf2cam.Scale = scale; mf2Elm.SetCamera(mf2cam); //Insert Map Frame 3 at random location MapFrame mf3Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e3, mapFrame.Map); mf3Elm.SetName("MF3"); Camera mf3cam = mf3Elm.Camera; mf3cam.X = x + (delta * 2); mf3cam.Y = y - delta; mf3cam.Scale = scale; mf3Elm.SetCamera(mf3cam); //Insert Map Frame 4 at random location MapFrame mf4Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e4, mapFrame.Map); mf4Elm.SetName("MF4"); Camera mf4cam = mf4Elm.Camera; mf4cam.X = x + (delta * 2); mf4cam.Y = y + delta; mf4cam.Scale = scale; mf4Elm.SetCamera(mf4cam); //Insert Map Frame 5 at random location MapFrame mf5Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e5, mapFrame.Map); mf5Elm.SetName("MF5"); Camera mf5cam = mf5Elm.Camera; mf5cam.X = x; mf5cam.Y = y + delta; mf5cam.Scale = scale; mf5Elm.SetCamera(mf5cam); //Insert Map Frame 6 at random location MapFrame mf6Elm = LayoutElementFactory.Instance.CreateMapFrame(layout, e6, mapFrame.Map); mf6Elm.SetName("MF6"); Camera mf6cam = mf6Elm.Camera; mf6cam.X = x - (delta * 2); mf6cam.Y = y + delta; mf6cam.Scale = scale; mf6Elm.SetCamera(mf6cam); //Create 6 polygon boxes that represent where the outer map frames need to be placed. Coordinate2D box1_ll = new Coordinate2D(4, 0.5); Coordinate2D box1_ur = new Coordinate2D(7, 3.5); Envelope box1_env = EnvelopeBuilder.CreateEnvelope(box1_ll, box1_ur); GraphicElement box1 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box1_env); box1.SetName("Rectangle 1"); Coordinate2D box2_ll = new Coordinate2D(7, 0.5); Coordinate2D box2_ur = new Coordinate2D(10, 3.5); Envelope box2_env = EnvelopeBuilder.CreateEnvelope(box2_ll, box2_ur); GraphicElement box2 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box2_env); box2.SetName("Rectangle 2"); Coordinate2D box3_ll = new Coordinate2D(10, 0.5); Coordinate2D box3_ur = new Coordinate2D(13, 3.5); Envelope box3_env = EnvelopeBuilder.CreateEnvelope(box3_ll, box3_ur); GraphicElement box3 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box3_env); box3.SetName("Rectangle 3"); Coordinate2D box4_ll = new Coordinate2D(10, 3.5); Coordinate2D box4_ur = new Coordinate2D(13, 6.5); Envelope box4_env = EnvelopeBuilder.CreateEnvelope(box4_ll, box4_ur); GraphicElement box4 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box4_env); box4.SetName("Rectangle 4"); Coordinate2D box5_ll = new Coordinate2D(7, 3.5); Coordinate2D box5_ur = new Coordinate2D(10, 6.5); Envelope box5_env = EnvelopeBuilder.CreateEnvelope(box5_ll, box5_ur); GraphicElement box5 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box5_env); box5.SetName("Rectangle 5"); Coordinate2D box6_ll = new Coordinate2D(4, 3.5); Coordinate2D box6_ur = new Coordinate2D(7, 6.5); Envelope box6_env = EnvelopeBuilder.CreateEnvelope(box6_ll, box6_ur); GraphicElement box6 = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, box6_env); box6.SetName("Rectangle 6"); //Find MainMF and set invisible MapFrame mainMF = layout.FindElement("Main MF") as MapFrame; mainMF.SetVisible(false); //Update Instructions TextElement steps = layout.FindElement("Instructions") as TextElement; string text = "<bol>Instructions: </bol>\n\n - Click the 'Play Game' command" as String; var stepsProp = steps.TextProperties; stepsProp.Text = text; steps.SetTextProperties(stepsProp); }); layoutView.ClearElementSelection(); }
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 }