3

I am in the process of generating hundreds of maps in ArcMap 10.3 from a few master templates. I recently found out that I have to add a small text box in the bottom-right hand corner of all the maps containing additional information (all the boxes will contain the same text and be placed in the exact same location).

Is there a way I can add the text box to the master templates and use Arcpy to copy & paste the text box on all the maps?

Trying to find a way not to do this manually.

asked Jan 19, 2017 at 18:18
4
  • are all these maps being generated from one mxd? or multiple? Commented Jan 19, 2017 at 18:23
  • They'll be based on several .mxds, but if it makes the answer to this question any easier, I can easily just put the text box in 1 master template and have Arcpy use that as the jumping-off point to copy/paste on all the rest. Commented Jan 19, 2017 at 18:30
  • 1
    You can't create new layout elements with arcpy, only copy and modify existing elements. You would have to tap into ArcObjects (which you can do through Python, although it's somewhat complicated) to move elements between maps or create new elements. Commented Jan 19, 2017 at 19:39
  • Thanks for the help, @phloem. I'll look into ArcObjects. Commented Jan 19, 2017 at 20:21

1 Answer 1

1

There is a workaround possible, if you already have got a textbox in your layout. You can use the .clone() - function to copy and paste a textbox in your layout. Now you can change the content with .text and use .elementPositionX and .elementPositionY to move the Textbox to you desired place. If you need to alter font, font size or else you can use formating tags to do so.

In the example below I also cloned a graphic rectangle and placed it around the new cloned textbox.

import arcpy
inputMap = r"D:\Textboxes.mxd"
outputMap = r"D:\Textboxes2.mxd"
mxd = arcpy.mapping.MapDocument(inputMap)
# get elemets according to element-name
Textorig = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Textorig")[0]
Frame = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT","Frame")[0]
# clone elements
Textorig.clone("_copy")
Frame.clone("_copy")
# alter elements 
Textorigcopy = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Textorig_copy")[0]
Textorigcopy.text = '<FNT size = "36"><CLR red = "255"><BOL><ITA>New Text</ITA></BOL></CLR></FNT>'
Textorigcopy.elementPositionX = 6.8883
Textorigcopy.elementPositionY = 21.6488
Framecopy = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT","Frame_copy")[0]
Framecopy.elementPositionX = 6.7135
Framecopy.elementPositionY = 21.5169
Framecopy.elementWidth = 6.1354
Framecopy.elementHeight = 1.7808
mxd.saveACopy(outputMap)
del mxd

enter image description here

answered Jun 30, 2017 at 9:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.