I'm wondering which interface will allow me to set the XY position of a text element in the page layout of my MXD. I have tried the IElement.Geometry.Envelope.PutCoords(Y, X) to no avail.


The way to move text elements around the page layout is to use ITransform2D. Below is some VBA showing how to do it:

Public Sub TextElementExample()
    ' Get map document
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    ' Get Pagelayout
    Dim pPageLayout As IPageLayout
    Set pPageLayout = pMxDoc.PageLayout

    ' Get Graphics container
    Dim pGraphicsContainer As IGraphicsContainer
    Set pGraphicsContainer = pPageLayout

    ' Create a point in page layout units
    Dim pPoint As IPoint
    Set pPoint = New Point
    pPoint.X = 10
    pPoint.Y = 10

    ' Create sample text
    Dim pTextElement As ITextElement
    Set pTextElement = New TextElement
    pTextElement.Text = "Some Sample Text"
    pTextElement.ScaleText = True

    'Add text to page layout
    Dim pElement As IElement
    Set pElement = pTextElement
    pElement.Geometry = pPoint
    pGraphicsContainer.AddElement pElement, 0

    ' Clone text element
    Dim pClone As IClone
    Set pClone = pElement
    Dim pElement2 As IElement
    Set pElement2 = pClone.Clone

    ' Now move new element and add to pagelayout
    Dim pTransform2D As ITransform2D
    Set pTransform2D = pElement2
    pTransform2D.Move 10, -5
    pGraphicsContainer.AddElement pElement2, 0

End Sub
  • This will certainly work! I was also wondering if there's a way to set/get the XY position properties of the text element. I recall from ArcPy that you can simply set the elementPositionX/Y properties to perform the transformation, do you know of an ArcObjects equivalent? – cevondanady Jun 6 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.