public static Task <bool> UpdatePictureElementAsync(string LayoutName, string PictureName, string PicturePath)
        {
            //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 picture element by name
                PictureElement picElm = lyt.FindElement(PictureName) as PictureElement;
                if (picElm == null)
                {
                    return false;
                }

                //Change the path to a new source
                picElm.SetSourcePath(PicturePath);

                return true;
            }));
        }
示例#2
0
        async public static void PictureElementSnippets()
        {
            #region PictureElement_SetSourcePath
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            await QueuedTask.Run(() =>
            {
                Layout layout         = layoutItem.GetLayout();
                PictureElement picElm = layout.FindElement("Rectangle") as PictureElement;

                picElm.SetSourcePath(@"C:\Some\New\Path\And\file.ext");
            });

            #endregion PictureElement_SetSourcePath
        }
示例#3
0
        public void snippets_UpdateElements()
        {
            double x = 0;
            double y = 0;

            #region Update Text Element properties

            // 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)
                    {
                        // Reference a text element by name
                        TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
                        if (txtElm != null)
                        {
                            // 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);
                        }
                    }
                });
            }
            #endregion

            #region Update a picture element

            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\somePic.jpg");
                    }
                }
            });
            #endregion

            #region Update a map surround

            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);
                    }
                }
            });
            #endregion

            #region Lock an element

            // 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.

            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
                        CIMElement CIMElement = element.GetDefinition() as CIMElement;
                        CIMElement.Locked     = true;
                        element.SetDefinition(CIMElement);
                    }
                }
            });

            #endregion

            #region Update an elements transparency

            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.
                        CIMGraphic CIMGraphic   = graphicElement.Graphic as CIMGraphic;
                        CIMGraphic.Transparency = 50; // mark it 50% transparent
                        graphicElement.SetGraphic(CIMGraphic);
                    }
                }
            });
            #endregion

            double xOffset = 0;
            double yOffset = 0;
            #region Clone an element

            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)
                    {
                        // clone and set the new x,y
                        GraphicElement cloneElement = graphicElement.Clone("Clone");
                        cloneElement.SetX(cloneElement.GetX() + xOffset);
                        cloneElement.SetY(cloneElement.GetY() + yOffset);
                    }
                }
            });
            #endregion
        }