Пример #1
0
        public static Task <bool> LockTOCElementAsync(string LayoutName, string ElementName, bool Toggle)
        {
            //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 an element by name
                Element elm = lyt.FindElement(ElementName);
                if (elm == null)
                {
                    return false;
                }

                //Modify the Locked property via the CIM
                CIMElement CIMElm = elm.GetDefinition() as CIMElement;
                CIMElm.Locked = Toggle;        //e.g. Toggle = true
                elm.SetDefinition(CIMElm);
                System.Windows.MessageBox.Show(string.Format("{0} is now locked in the TOC.", elm.Name));

                return true;
            }));
        }
Пример #2
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
        }
Пример #3
0
        async public static void ElementSnippets()
        {
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            layout     = await QueuedTask.Run(() => layoutItem.GetLayout());

            Element element = layout.FindElement("Group Element");

            await QueuedTask.Run(() =>
            {
                #region Element_GetAnchor
                //Note: call within QueuedTask.Run()
                Anchor elmAnchor = element.GetAnchor();
                #endregion Element_GetAnchor

                #region Element_GetDefinition
                //Note: call within QueuedTask.Run()
                CIMElement CIMElm = element.GetDefinition();
                #endregion Element_GetDefinition

                #region Element_GetHeight
                //Note: call within QueuedTask.Run()
                double elmHeight = element.GetHeight();
                #endregion Element_GetHeight

                #region Element_GetLockedAspectRatio
                //Note: call within QueuedTask.Run()
                bool elmLocked = element.GetLockedAspectRatio();
                #endregion Element_GetLockedAspectRatio

                #region Element_GetRotation
                //Note: call within QueuedTask.Run()
                double elmRot = element.GetRotation();
                #endregion Element_GetRotation

                #region Element_GetWidth
                //Note: call within QueuedTask.Run()
                double elmWidth = element.GetWidth();
                #endregion Element_GetWidth

                #region Element_GetX
                //Note: call within QueuedTask.Run()
                double elmX = element.GetX();
                #endregion Element_GetX

                #region Element_GetY
                //Note: call within QueuedTask.Run()
                double elmY = element.GetY();
                #endregion Element_GetY

                #region Element_SetAnchor
                //Note: call within QueuedTask.Run()
                element.SetAnchor(Anchor.CenterPoint);
                #endregion Element_SetAnchor

                #region Element_SetDefinition
                //Note: call within QueuedTask.Run()
                element.SetDefinition(CIMElm);
                #endregion Element_SetDefinition

                #region Element_SetHeight
                //Note: call within QueuedTask.Run()
                element.SetHeight(11);
                #endregion Element_SetHeight

                #region Element_SetLocked
                //Note: call within QueuedTask.Run()
                element.SetLocked(true);
                #endregion Element_SetLocked

                #region Element_SetLockedAspectRatio
                //Note: call within QueuedTask.Run()
                element.SetLockedAspectRatio(true);
                #endregion Element_SetLockedAspectRatio

                #region Element_SetName
                //Note: call within QueuedTask.Run()
                element.SetName("New Name");
                #endregion Element_SetName

                #region Element_SetRotation
                //Note: call within QueuedTask.Run()
                element.SetRotation(22.5);
                #endregion Element_SetRotation

                #region Element_SetTOCPositionAbsolute
                //Note: call within QueuedTask.Run()
                element.SetTOCPositionAbsolute(layout, true);
                #endregion Element_SetTOCPositionAbsolute

                #region Element_SetTOCPositionRelative
                //Note: call within QueuedTask.Run()
                element.SetTOCPositionRelative(element, true);
                #endregion Element_SetTOCPositionRelative

                #region Element_SetVisible
                //Note: call within QueuedTask.Run()
                element.SetVisible(true);
                #endregion Element_SetVisible

                #region Element_SetWidth
                //Note: call within QueuedTask.Run()
                element.SetX(8.5);
                #endregion Element_SetWidth

                #region Element_SetX
                //Note: call within QueuedTask.Run()
                element.SetX(5.5);
                #endregion Element_SetX

                #region Element_SetY
                //Note: call within QueuedTask.Run()
                element.SetY(1.25);
                #endregion Element_SetY
            });
        }
Пример #4
0
        async public static void MethodSnippets()
        {
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            layout     = await QueuedTask.Run(() => layoutItem.GetLayout());

            Element element = layout.FindElement("Group Element");


            #region Element_ConvertToGraphics
            //Convert a legend to a graphic and move the Title to the bottom of the legend and also move
            //the label in the contents pane to the bottom of the list.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                Legend leg          = layout.FindElement("Legend") as Legend;
                GroupElement result = leg.ConvertToGraphics().First() as GroupElement;
                Element firstElm    = result.Elements.First(); //Note: Bottom element is first in drawing order.
                foreach (Element elm in result.Elements)
                {
                    if (elm.Name == "Title")
                    {
                        elm.SetY(firstElm.GetY() - 0.25);          //Move title below other legend elements
                        elm.SetTOCPositionAbsolute(result, false); // Move Title item in TOC to bottom as well
                    }
                }
            });

            #endregion Element_ConvertToGraphics

            #region Element_GetSetAnchor
            //Change the element's anchor position

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                Anchor elmAnchor = element.GetAnchor();
                elmAnchor        = Anchor.CenterPoint;

                element.SetAnchor(elmAnchor); //You don't have to get to set; a shortcut would be: element.SetAnchor(Anchor.CenterPoint);
            });

            #endregion Element_GetSetAnchor

            #region Element_GetCustomProperty
            //Get a custom property that has been previously set.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                String custProp = element.GetCustomProperty("MyKeyString");
            });

            #endregion Element_GetCustomProperty

            #region Element_GetSetDefinition
            //Modify an element's CIM properties.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                CIMElement CIMElm = element.GetDefinition();

                //Modify a CIM value

                element.SetDefinition(CIMElm);
            });

            #endregion Element_GetSetDefinition

            #region Element_GetSetHeight
            //Modify an element's hieght.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmHeight = element.GetHeight();
                elmHeight        = 11;

                element.SetHeight(elmHeight); //You don't have to get to set; a shortcut would be: element.SetHieght(11);
            });

            #endregion Element_GetSetHeight

            #region Element_SetLocked
            //Modify an element's locked state if it isn't already

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                if (!element.IsLocked)
                {
                    element.SetLocked(true);
                }
            });

            #endregion Element_GetSetLocked

            #region Element_GetSetLockedAspectRatio
            //Modify an element's aspect ratio.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                bool elmLocked = element.GetLockedAspectRatio();
                elmLocked      = false;                  //Turn off the locked state.

                element.SetLockedAspectRatio(elmLocked); //You don't have to get to set; a shortcut would be: element.SetLockedAspectRatio(false);
            });

            #endregion Element_GetSetLockedAspectRatio

            #region Element_GetSetRotation
            //Modify and element's rotation value.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmRot = element.GetRotation();
                elmRot        = 22.5;

                element.SetRotation(elmRot); //You don't have to get to set; a shortcut would be: element.SetRotation(22.5);
            });

            #endregion Element_GetSetRotation

            #region Element_GetSetWidth
            //Modify an element's width.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmWidth = element.GetWidth();
                elmWidth        = 8.5;

                element.SetWidth(elmWidth); //You don't have to get to set; a shortcut would be: element.SetWidth(8.5);
            });

            #endregion Element_GetSetWidth

            #region Element_GetSetX
            //Modify an element's X position.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmX = element.GetX();
                elmX        = 4.25;

                element.SetX(elmX); //You don't have to get to set; a shortcut would be: element.SetX(4.25);
            });

            #endregion Element_GetSetX

            #region Element_GetSetY
            //Modify an element's Y position.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                double elmY = element.GetY();
                elmY        = 5.5;

                element.SetY(elmY); //You don't have to get to set; a shortcut would be: element.SetY(5.5);
            });

            #endregion Element_GetSetY

            #region Element_SetCustomProperty
            //Set a custom property on an element.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetCustomProperty("MyKeyString", "MyValueString");
            });

            #endregion Element_SetCustomProperty

            #region Element_SetName
            //Modify an element's name.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetName("New Name");
            });

            #endregion Element_SetName

            #region Element_SetTOCPositionAbsolute
            //Move an element to the top of the TOC

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetTOCPositionAbsolute(layout, true);
            });

            #endregion Element_SetTOCPositionAbsolute

            #region Element_SetTOCPositionRelative
            //Move a layout element above an existing layout element.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetTOCPositionRelative(element, true);
            });

            #endregion Element_SetTOCPositionRelative

            #region Element_SetVisible
            //Modify an element's visibility.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                element.SetVisible(true); //Turn it on / make visible.
            });

            #endregion Element_SetVisible
        }