Ejemplo n.º 1
0
        public static Task <bool> UpdateElementTransparencyAsync(string LayoutName, string ElementName, int TransValue)
        {
            //Reference a layoutitem in a project by name
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));

            if (layoutItem == null)
            {
                return(Task.FromResult(false));
            }

            return(QueuedTask.Run <bool>(() =>
            {
                //Reference and load the layout associated with the layout item
                Layout lyt = layoutItem.GetLayout();

                //Reference a element by name
                GraphicElement graElm = lyt.FindElement(ElementName) as GraphicElement;
                if (graElm == null)
                {
                    return false;
                }

                //Modify the Transparency property that exists only in the CIMGraphic class.
                CIMGraphic CIMGra = graElm.GetGraphic() as CIMGraphic;
                CIMGra.Transparency = TransValue;     //e.g., TransValue = 50
                graElm.SetGraphic(CIMGra);

                return true;
            }));
        }
Ejemplo n.º 2
0
        //async public static void CreateElementSnippets()
        //{
        //  //There are already many Create element snippets in the PRO snippets section.  This section will only contain examples that are NOT in the Pro snippets section
        //  //Pro snippets region names includes:
        //  //    Create point graphic with symbology
        //  //    Create line graphic with symbology
        //  //    Create rectangle graphic with simple symbology
        //  //    Create text element with basic font properties
        //  //    Create rectangle text with more advanced symbol settings
        //  //    Create a new picture element with advanced symbol settings
        //  //    Create a map frame and zoom to a bookmark
        //  //    Create a legend for a specific map frame
        //  //    Creating group elements

        //  LayoutView lytView = LayoutView.Active;
        //  Layout layout = lytView.Layout;

        //  #region Create_BeizierCurve
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D pt1 = new Coordinate2D(1, 7.5);
        //    Coordinate2D pt2 = new Coordinate2D(1.66, 8);
        //    Coordinate2D pt3 = new Coordinate2D(2.33, 7.1);
        //    Coordinate2D pt4 = new Coordinate2D(3, 7.5);
        //    CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
        //    CubicBezierSegment bezSeg = bez.ToSegment();
        //    Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg);

        //    //Set symbology, create and add element to layout
        //    CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
        //    GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym);
        //    bezElm.SetName("New Bezier Curve");
        //  });
        //  #endregion Create_BeizierCurve

        //  #region Create_freehand
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    List<Coordinate2D> plCoords = new List<Coordinate2D>();
        //    plCoords.Add(new Coordinate2D(1.5, 10.5));
        //    plCoords.Add(new Coordinate2D(1.25, 9.5));
        //    plCoords.Add(new Coordinate2D(1, 10.5));
        //    plCoords.Add(new Coordinate2D(0.75, 9.5));
        //    plCoords.Add(new Coordinate2D(0.5, 10.5));
        //    plCoords.Add(new Coordinate2D(0.5, 1));
        //    plCoords.Add(new Coordinate2D(0.75, 2));
        //    plCoords.Add(new Coordinate2D(1, 1));
        //    Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);

        //    //Set symbolology, create and add element to layout
        //    CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
        //    GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym);
        //    lineElm.SetName("New Freehand");
        //  });
        //  #endregion Create_freehand

        //  #region Create_polygon_poly
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
        //    plyCoords.Add(new Coordinate2D(1, 7));
        //    plyCoords.Add(new Coordinate2D(2, 7));
        //    plyCoords.Add(new Coordinate2D(2, 6.7));
        //    plyCoords.Add(new Coordinate2D(3, 6.7));
        //    plyCoords.Add(new Coordinate2D(3, 6.1));
        //    plyCoords.Add(new Coordinate2D(1, 6.1));
        //    Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

        //    //Set symbolology, create and add element to layout
        //    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
        //    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
        //    GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
        //    polyElm.SetName("New Polygon");
        //  });
        //  #endregion Create_polygon_poly

        //  #region Create_polygon_env
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build 2D envelope
        //    Coordinate2D env_ll = new Coordinate2D(1.0, 4.75);
        //    Coordinate2D env_ur = new Coordinate2D(3.0, 5.75);
        //    Envelope env = EnvelopeBuilder.CreateEnvelope(env_ll, env_ur);

        //    //Set symbolology, create and add element to layout
        //    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
        //    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
        //    GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, env, polySym);
        //    polyElm.SetName("New Polygon");
        //  });
        //  #endregion Create_polygon_env

        //  #region Create_circle
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(2, 4);
        //    EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
        //    EllipticArcSegment cir = eabCir.ToSegment();

        //    //Set symbolology, create and add element to layout
        //    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash);
        //    CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
        //    GraphicElement cirElm = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym);
        //    cirElm.SetName("New Circle");
        //  });
        //  #endregion Create_circle

        //  #region Create_ellipse
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(2, 2.75);
        //    EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
        //    EllipticArcSegment ellipse = eabElp.ToSegment();

        //    //Set symbolology, create and add element to layout
        //    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot);
        //    CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline);
        //    GraphicElement elpElm = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym);
        //    elpElm.SetName("New Ellipse");
        //  });
        //  #endregion Create_ellipse

        //  #region Create_lasso
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
        //    plyCoords.Add(new Coordinate2D(1, 1));
        //    plyCoords.Add(new Coordinate2D(1.25, 2));
        //    plyCoords.Add(new Coordinate2D(1.5, 1.1));
        //    plyCoords.Add(new Coordinate2D(1.75, 2));
        //    plyCoords.Add(new Coordinate2D(2, 1.1));
        //    plyCoords.Add(new Coordinate2D(2.25, 2));
        //    plyCoords.Add(new Coordinate2D(2.5, 1.1));
        //    plyCoords.Add(new Coordinate2D(2.75, 2));
        //    plyCoords.Add(new Coordinate2D(3, 1));
        //    Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

        //    //Set symbolology, create and add element to layout
        //    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
        //    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
        //    GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
        //    polyElm.SetName("New Lasso");
        //  });
        //  #endregion Create_lasso

        //  #region Create_CurveText
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D pt1 = new Coordinate2D(3.6, 7.5);
        //    Coordinate2D pt2 = new Coordinate2D(4.26, 8);
        //    Coordinate2D pt3 = new Coordinate2D(4.93, 7.1);
        //    Coordinate2D pt4 = new Coordinate2D(5.6, 7.5);
        //    CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
        //    CubicBezierSegment bezSeg = bez.ToSegment();
        //    Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg);

        //    //Set symbolology, create and add element to layout
        //    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
        //    GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym);
        //    bezTxtElm.SetName("New Splinned Text");
        //  });
        //  #endregion Create_CurveText

        //  #region Create_PolygonText
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
        //    plyCoords.Add(new Coordinate2D(3.5, 7));
        //    plyCoords.Add(new Coordinate2D(4.5, 7));
        //    plyCoords.Add(new Coordinate2D(4.5, 6.7));
        //    plyCoords.Add(new Coordinate2D(5.5, 6.7));
        //    plyCoords.Add(new Coordinate2D(5.5, 6.1));
        //    plyCoords.Add(new Coordinate2D(3.5, 6.1));
        //    Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

        //    //Set symbolology, create and add element to layout
        //    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
        //    string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String;
        //    GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym);
        //    polyTxtElm.SetName("New Polygon Text");

        //    //(Optionally) Modify paragraph border
        //    CIMGraphic polyTxtGra = polyTxtElm.Graphic;
        //    CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
        //    cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
        //    cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
        //    polyTxtElm.SetGraphic(polyTxtGra);
        //  });

        //  #endregion Create_PolygonText

        //  #region Create_CircleText
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(4.5, 4);
        //    EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
        //    EllipticArcSegment cir = eabCir.ToSegment();

        //    //Set symbolology, create and add element to layout
        //    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular");
        //    string text = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle";
        //    GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym);
        //    cirTxtElm.SetName("New Circle Text");

        //    //(Optionally) Modify paragraph border
        //    CIMGraphic cirTxtGra = cirTxtElm.Graphic;
        //    CIMParagraphTextGraphic cimCirTxtGra = cirTxtGra as CIMParagraphTextGraphic;
        //    cimCirTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
        //    cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
        //    cirTxtElm.SetGraphic(cirTxtGra);
        //  });
        //  #endregion Create_CircleText

        //  #region Create_EllipseText
        //  await QueuedTask.Run(() =>
        //  {
        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(4.5, 2.75);
        //    EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
        //    EllipticArcSegment ellipse = eabElp.ToSegment();

        //    //Set symbolology, create and add element to layout
        //    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular");
        //    string text = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse";
        //    GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym);
        //    elpTxtElm.SetName("New Ellipse Text");

        //    //(Optionally) Modify paragraph border
        //    CIMGraphic elpTxtGra = elpTxtElm.Graphic;
        //    CIMParagraphTextGraphic cimElpTxtGra = elpTxtGra as CIMParagraphTextGraphic;
        //    cimElpTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
        //    cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
        //    elpTxtElm.SetGraphic(elpTxtGra);
        //  });
        //  #endregion Create_EllipseText

        //  MapFrame mfElm = null;

        //  #region Create_MapFrame
        //  //This example creates a new map frame and changes the camera scale.
        //  await QueuedTask.Run(() =>
        //  {
        //      //Build geometry
        //      Coordinate2D ll = new Coordinate2D(6.0, 8.5);
        //      Coordinate2D ur = new Coordinate2D(8.0, 10.5);
        //      Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur);

        //      //Reference map, create MF and add to layout
        //      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
        //      Map mfMap = mapPrjItem.GetMap();
        //      mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap);
        //      mfElm.SetName("New Map Frame");

        //      //Set the camera
        //      Camera camera = mfElm.Camera;
        //      camera.Scale = 24000;
        //      mfElm.SetCamera(camera);
        //  });
        //  #endregion Create_MapFrame

        //  #region Create_ScaleBar
        //  await QueuedTask.Run(() =>
        //  {
        //    //Reference a North Arrow in a style
        //    StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
        //    ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0];

        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(7, 8);

        //    //Reference MF, create north arrow and add to layout
        //    MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
        //    if (mf == null)
        //    {
        //      ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
        //      return;
        //    }
        //    ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm);
        //    sbElm.SetName("New Scale Bar");
        //    sbElm.SetWidth(2);
        //    sbElm.SetX(6);
        //    sbElm.SetY(7.5);
        //  });
        //  #endregion Create_ScaleBar

        //  #region Create_NorthArrow
        //  await QueuedTask.Run(() =>
        //  {
        //    //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];

        //    //Build geometry
        //    Coordinate2D center = new Coordinate2D(7, 5.5);

        //    //Reference MF, create north arrow and add to layout
        //    MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
        //    if (mf == null)
        //    {
        //      ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
        //      return;
        //    }
        //    NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm);
        //    arrowElm.SetName("New North Arrow");
        //    arrowElm.SetHeight(1.75);
        //    arrowElm.SetX(7);
        //    arrowElm.SetY(6);
        //  });
        //  #endregion Create_NorthArrow

        //  #region Create_Group_Root
        //  //Create an empty group element at the root level of the contents pane
        //  //Note: call within QueuedTask.Run()
        //  GroupElement grp1 = LayoutElementFactory.Instance.CreateGroupElement(layout);
        //  grp1.SetName("Group");
        //  #endregion

        //  #region Create_Group_Group
        //  //Create a group element inside another group element
        //  //Note: call within QueuedTask.Run()
        //  GroupElement grp2 = LayoutElementFactory.Instance.CreateGroupElement(grp1);
        //  grp2.SetName("Group in Group");
        //  #endregion


        //}

        async public static void GraphicElementSnippets()
        {
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            lyt        = await QueuedTask.Run(() => layoutItem.GetLayout());

            GraphicElement graElm = lyt.FindElement("Rectangle") as GraphicElement;

            CIMGraphic CIMGra = graElm.GetGraphic() as CIMGraphic;

            await QueuedTask.Run(() =>
            {
                #region GraphicElement_Clone
                //Note: call within QueuedTask.Run()
                GraphicElement cloneElm = graElm.Clone("Clone");
                #endregion GraphicElement_Clone

                #region GraphicElement_SetGraphic
                //Note: call within QueuedTask.Run()
                graElm.SetGraphic(CIMGra);
                #endregion GraphicElement_SetGraphic
            });
        }
Ejemplo n.º 3
0
        async public static void CreateElementSnippets()
        {
            //There are already many Create element snippets in the PRO snippets section.  This section will only contain examples that are NOT in the Pro snippets section
            //Pro snippets region names includes:
            //    Create point graphic with symbology
            //    Create line graphic with symbology
            //    Create rectangle graphic with simple symbology
            //    Create text element with basic font properties
            //    Create rectangle text with more advanced symbol settings
            //    Create a new picture element with advanced symbol settings
            //    Create a map frame and zoom to a bookmark
            //    Create a legend for a specific map frame
            //    Creating group elements

            LayoutView lytView = LayoutView.Active;
            Layout     layout  = lytView.Layout;

            #region Create_BezierCurve
            //Create a beizier curve element with a simple line style.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D pt1          = new Coordinate2D(1, 7.5);
                Coordinate2D pt2          = new Coordinate2D(1.66, 8);
                Coordinate2D pt3          = new Coordinate2D(2.33, 7.1);
                Coordinate2D pt4          = new Coordinate2D(3, 7.5);
                CubicBezierBuilder bez    = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
                CubicBezierSegment bezSeg = bez.ToSegment();
                Polyline bezPl            = PolylineBuilder.CreatePolyline(bezSeg);

                //Set symbology, create and add element to layout
                CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
                GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym);
                bezElm.SetName("New Bezier Curve");
            });

            #endregion Create_BezierCurve

            #region Create_freehand
            //Create a graphic freehand element with a simple line style.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plCoords = new List <Coordinate2D>();
                plCoords.Add(new Coordinate2D(1.5, 10.5));
                plCoords.Add(new Coordinate2D(1.25, 9.5));
                plCoords.Add(new Coordinate2D(1, 10.5));
                plCoords.Add(new Coordinate2D(0.75, 9.5));
                plCoords.Add(new Coordinate2D(0.5, 10.5));
                plCoords.Add(new Coordinate2D(0.5, 1));
                plCoords.Add(new Coordinate2D(0.75, 2));
                plCoords.Add(new Coordinate2D(1, 1));
                Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);

                //Set symbolology, create and add element to layout
                CIMLineSymbol lineSym  = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
                GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym);
                lineElm.SetName("New Freehand");
            });

            #endregion Create_freehand

            #region Create_polygon_poly
            //Create a polygon graphic with simple line and fill styles.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(1, 7));
                plyCoords.Add(new Coordinate2D(2, 7));
                plyCoords.Add(new Coordinate2D(2, 6.7));
                plyCoords.Add(new Coordinate2D(3, 6.7));
                plyCoords.Add(new Coordinate2D(3, 6.1));
                plyCoords.Add(new Coordinate2D(1, 6.1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
                GraphicElement polyElm   = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
                polyElm.SetName("New Polygon");
            });

            #endregion Create_polygon_poly

            #region Create_polygon_env
            //Create a polygon graphic using an envelope with simple line and fill styles.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build 2D envelope
                Coordinate2D env_ll = new Coordinate2D(1.0, 4.75);
                Coordinate2D env_ur = new Coordinate2D(3.0, 5.75);
                Envelope env        = EnvelopeBuilder.CreateEnvelope(env_ll, env_ur);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
                GraphicElement polyElm   = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, env, polySym);
                polyElm.SetName("New Polygon");
            });

            #endregion Create_polygon_env

            #region Create_circle
            //Create a circle graphic element using a simple line and fill styles.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center       = new Coordinate2D(2, 4);
                EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment cir    = eabCir.ToSegment();

                //Set symbolology, create and add element to layout
                CIMStroke outline          = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash);
                CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline);
                GraphicElement cirElm      = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym);
                cirElm.SetName("New Circle");
            });

            #endregion

            #region Create_ellipse
            //Create an ellipse graphic with simple line and fill styles.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center        = new Coordinate2D(2, 2.75);
                EllipticArcBuilder eabElp  = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment ellipse = eabElp.ToSegment();

                //Set symbolology, create and add element to layout
                CIMStroke outline           = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot);
                CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline);
                GraphicElement elpElm       = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym);
                elpElm.SetName("New Ellipse");
            });

            #endregion

            #region Create_lasso
            //Create a graphic lasso element with simple line and fill styles.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(1, 1));
                plyCoords.Add(new Coordinate2D(1.25, 2));
                plyCoords.Add(new Coordinate2D(1.5, 1.1));
                plyCoords.Add(new Coordinate2D(1.75, 2));
                plyCoords.Add(new Coordinate2D(2, 1.1));
                plyCoords.Add(new Coordinate2D(2.25, 2));
                plyCoords.Add(new Coordinate2D(2.5, 1.1));
                plyCoords.Add(new Coordinate2D(2.75, 2));
                plyCoords.Add(new Coordinate2D(3, 1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMStroke outline        = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
                GraphicElement polyElm   = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym);
                polyElm.SetName("New Lasso");
            });

            #endregion Create_lasso

            #region Create_CurveText
            //Create curve text with basic text properties.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D pt1          = new Coordinate2D(3.6, 7.5);
                Coordinate2D pt2          = new Coordinate2D(4.26, 8);
                Coordinate2D pt3          = new Coordinate2D(4.93, 7.1);
                Coordinate2D pt4          = new Coordinate2D(5.6, 7.5);
                CubicBezierBuilder bez    = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
                CubicBezierSegment bezSeg = bez.ToSegment();
                Polyline bezPl            = PolylineBuilder.CreatePolyline(bezSeg);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
                GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym);
                bezTxtElm.SetName("New Splinned Text");
            });

            #endregion Create_CurveText

            #region Create_PolygonText
            //Create polygon paragraph text with basic text properties.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                List <Coordinate2D> plyCoords = new List <Coordinate2D>();
                plyCoords.Add(new Coordinate2D(3.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 7));
                plyCoords.Add(new Coordinate2D(4.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.7));
                plyCoords.Add(new Coordinate2D(5.5, 6.1));
                plyCoords.Add(new Coordinate2D(3.5, 6.1));
                Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym         = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
                string text               = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String;
                GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym);
                polyTxtElm.SetName("New Polygon Text");

                //(Optionally) Modify paragraph border
                CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
                CIMParagraphTextGraphic cimPolyTxtGra   = polyTxtGra as CIMParagraphTextGraphic;
                cimPolyTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                polyTxtElm.SetGraphic(polyTxtGra);
            });

            #endregion Create_PolygonText

            #region Create_CircleText
            //Create circle paragraph text with basic text settings and optionally a modified border.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center       = new Coordinate2D(4.5, 4);
                EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment cir    = eabCir.ToSegment();

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular");
                string text              = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle";
                GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym);
                cirTxtElm.SetName("New Circle Text");

                //(Optionally) Modify paragraph border
                CIMGraphic cirTxtGra = cirTxtElm.GetGraphic();
                CIMParagraphTextGraphic cimCirTxtGra   = cirTxtGra as CIMParagraphTextGraphic;
                cimCirTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                cirTxtElm.SetGraphic(cirTxtGra);
            });

            #endregion

            #region Create_EllipseText
            //Create ellipse paragraph text with basic text settings and optionally a modified border.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D center        = new Coordinate2D(4.5, 2.75);
                EllipticArcBuilder eabElp  = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
                EllipticArcSegment ellipse = eabElp.ToSegment();

                //Set symbolology, create and add element to layout
                CIMTextSymbol sym        = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular");
                string text              = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse";
                GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym);
                elpTxtElm.SetName("New Ellipse Text");

                //(Optionally) Modify paragraph border
                CIMGraphic elpTxtGra = elpTxtElm.GetGraphic();
                CIMParagraphTextGraphic cimElpTxtGra   = elpTxtGra as CIMParagraphTextGraphic;
                cimElpTxtGra.Frame.BorderSymbol        = new CIMSymbolReference();
                cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
                elpTxtElm.SetGraphic(elpTxtGra);
            });

            #endregion Create_EllipseText

            MapFrame mfElm = null;

            #region Create_MapFrame
            //Creates a new map frame and changes the camera's scale.

            //Constuct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Build geometry
                Coordinate2D ll = new Coordinate2D(6.0, 8.5);
                Coordinate2D ur = new Coordinate2D(8.0, 10.5);
                Envelope env    = EnvelopeBuilder.CreateEnvelope(ll, ur);

                //Reference map, create MF and add to layout
                MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map"));
                Map mfMap = mapPrjItem.GetMap();
                mfElm     = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap);
                mfElm.SetName("New Map Frame");

                //Set the camera
                Camera camera = mfElm.Camera;
                camera.Scale  = 24000;
                mfElm.SetCamera(camera);
            });

            #endregion Create_MapFrame

            #region Create_ScaleBar
            //Create a scale bar for a specific map frame and assign a scale bar style item.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //Reference a North Arrow in a style
                StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
                ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0];

                //Build geometry
                Coordinate2D center = new Coordinate2D(7, 8);

                //Reference MF, create north arrow and add to layout
                MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
                if (mf == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm);
                sbElm.SetName("New Scale Bar");
                sbElm.SetWidth(2);
                sbElm.SetX(6);
                sbElm.SetY(7.5);
            });

            #endregion Create_ScaleBar

            #region Create_NorthArrow
            //Create a north arrow for a specific map frame and assign a north arrow style item.

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                //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];

                //Build geometry
                Coordinate2D center = new Coordinate2D(7, 5.5);

                //Reference MF, create north arrow and add to layout
                MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
                if (mf == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
                    return;
                }
                NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm);
                arrowElm.SetName("New North Arrow");
                arrowElm.SetHeight(1.75);
                arrowElm.SetX(7);
                arrowElm.SetY(6);
            });

            #endregion Create_NorthArrow

            #region Create_Empty_Group_Root
            //Create an empty group element at the root level of the contents pane.


            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                GroupElement emptyGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout);
                emptyGroupAtRoot.SetName("Empty group at root");
            });

            #endregion

            #region Create_Empty_Group_Group
            //Create an empty group element at the root level of another group element.

            //Find an existing group element
            GroupElement existingGroupAtRoot = layout.FindElement("Empty group at root") as GroupElement;

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                GroupElement emptyGroupInGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(existingGroupAtRoot);
                emptyGroupInGroupAtRoot.SetName("Empty group in group at root");
            });

            #endregion

            #region Create_Group_With_Single_Element_Root
            //Create a group with a single element at the root level of the contents pane.

            //Find an existing element
            Element titleElm = layout.FindElement("Title") as Element;

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                GroupElement groupWithSingleElementAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, titleElm);
                groupWithSingleElementAtRoot.SetName("Group with single element at root");
            });

            #endregion

            #region Create_Group_With_List_Elements_Root
            //Create a group with a list of elements at the root level of the contents pane.

            //Find an existing elements
            Element scaleBar   = layout.FindElement("Scale Bar") as Element;
            Element northArrow = layout.FindElement("North Arrow") as Element;
            Element legend     = layout.FindElement("Legend") as Element;

            //Build a list and add the elements
            List <Element> elmList = new List <Element>
            {
                scaleBar,
                northArrow,
                legend
            };

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                GroupElement groupWithListOfElementsAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmList);
                groupWithListOfElementsAtRoot.SetName("Group with list of elements at root");
            });

            #endregion

            #region Create_Group_With_List_Element_Names_Root
            //Create a group using a list of element names at the root level of the contents pane.

            //Build list of element names
            var elmNameList = new[] { "Table Frame", "Chart Frame" };

            //Construct on the worker thread
            await QueuedTask.Run(() =>
            {
                GroupElement groupWithListOfElementNamesAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmNameList);
                groupWithListOfElementNamesAtRoot.SetName("Group with list of element names at root");
            });

            #endregion
        }