Select to view content in your preferred language

Place IGroupElement at Position XY in Layout

926
3
10-13-2011 12:02 AM
HenryColgate
Regular Contributor
Does anyone know how to move a Group Element or even just a regular old ELement to a specific XY on the Layout View?

I've tried setting it like I do for the Text Element below but just change ITextElement for IGroupElement and TextElementCLass for GroupElementClass :


        ESRI.ArcGIS.Carto.IElement element = new ESRI.ArcGIS.Carto.TextElementClass();
        ESRI.ArcGIS.Carto.ITextElement textElement = (ESRI.ArcGIS.Carto.ITextElement)element;

        ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
        point.X = 5;       
        point.Y = 10;

        element_TableField.Geometry = point;


But it fails with values outside expected range.

Is there an easy way to set the Anchor Point to a specific XY coordinate on the Page Layout?  This would be really good if it can be moved as IElement so I can use it for everything.  It is painfully easy in Python but not being able to create Elements kind of ruined the good time I was having there...
0 Kudos
3 Replies
JamesCrandall
MVP Frequent Contributor
Here is a snippet from an implementation I have that places a TextElement onto a LayoutView.  From what I recall, it was kind of tricky to determine the actual coords for the PutCoords method of the IEnvelope and I just fiddled with it until I got it to the desired location, so hopefully someone can add to this posting.

Good luck!

        Dim pActiveView As IActiveView
        Dim pEnv As IEnvelope
        pActiveView = pMxDoc.PageLayout
        pEnv = New Envelope

        Dim pTextElement As ITextElement
        pTextElement = New TextElement

        pTextElement.Text = "blah, blah""

        'Set font
        Dim pTextSym As IFormattedTextSymbol
        pTextSym = New TextSymbol
        Dim pFont As stdole.IFontDisp
        pFont = New stdole.StdFont
        pFont.Name = "Times New Roman"
        pFont.Size = 23
        pFont.Bold = True
        pTextSym.Font = pFont

        pTextElement.Symbol = pTextSym

        pEnv.PutCoords(4.5, 7, 4.5, 7) 'this was a bit tricky to specifically determine where to place

        Dim pElem As IElement
        pElem = pTextElement
        pElem.Geometry = pEnv
        Dim pGc As IGraphicsContainer
        pGc = pMxDoc.PageLayout
        pGc.AddElement(pElem, 0)
0 Kudos
HenryColgate
Regular Contributor
Cheers for the info.  Part of the reason I wanted to move grouped data is that they are created dynamically and then need to be placed.  This means that figuring out the location and sticking the text in the middle was a major issue.

I am now setting the location of the text inside a drawn box by using the font size and associated proportions.

I will try and post the code if it holds up after testing.
0 Kudos
HenryColgate
Regular Contributor
It looks like you can shuffle anything about using ITransform2D.

I have used it to move my combined elements.  I assume it works for other map document Elements also.

This means that I just create the element off to the side one over the other and then shift it to the place on the map document I need it.

Cheers
0 Kudos