0

I have multiple MXDs which have linked Word documents added using Insert Object. These Word documents change frequently and need to be updated in the maps. The only way I have found so far, from searches and Esri documentation, requires the MXD to be opened and the linked object double-clicked.

I'm looking for a way to do this using ArcPy, so that the process can be done in batch and without manual MXD opening.

Is there a way to refresh linked objects inserted into ArcMap without manually opening each MXD using ArcPy?

This is in ArcGIS Desktop 10.6.

3
  • 1
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. If you need to also ask about doing this using ArcObjects then please do that in a separate question, and include a code attempt.
    – PolyGeo
    Sep 8 at 19:29
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Sep 8 at 20:32
  • My apologies if this didn't fit the normal question format. I've tried to re-phrase the question to be more clear and direct. Thanks
    – George P.
    Sep 8 at 20:45
0

The refreshing of a linked Word document does not automatically happen as you have discovered and stated in the KB document. Amazingly this was reported in 2016 and ESRI have still (and I guess highly unlikely) not fixed it.

But all it not lost! I experimented with some code, running it in the Python console in Arcmap and I managed to get the layout linked object to refresh.

The trick is that the object must be named uniquely to identify it from all other graphic elements in the layout. I used a simple naming convention of "w0", I will explain the number portion a bit later.

First ensure you linked correctly as shown below (note checkbox tick):

Insert object dialog

Now ensure our linked word document object has the name "w0"

Element properties dialog

Now here is the code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"CURRENT")

# Code assumes element is tagged with a consistent name that is different to all other names to identify it as a linked word document
# in this example the graphic element that is a linked word document is initially named w0

for elm in arcpy.mapping.ListLayoutElements(mxd,"GRAPHIC_ELEMENT","w*"):
    name = elm.name # returns something like w1
    print(name)

    # Get numeric portion of name and increment
    n = int(name[1:])
    n += 1
    newname = "w" + str(n)

    # Clone element and destroy old one
    elm.clone(newname) # Creates a copy with the odd name of w1w2
    elm.delete()

    # We need to correct the cloned name
    oddname = name + newname
    for elm2 in arcpy.mapping.ListLayoutElements(mxd,"GRAPHIC_ELEMENT",oddname):
        elm2.name = newname

arcpy.RefreshActiveView()

The code locates the element by name, increments the number portion so w0 becomes w1 , then clones it and deletes the old graphic element. Final step is to reset the name for the cloned element back to the format w1. The act of cloning and resetting its name has the effect of double clicking on the element to get it to refresh.

Note: I ran this from the python console within ArcMap and it worked well, I have not tried to run it outside an ArcMap session, that's for you to explore if need be.

4
  • Thanks for the detailed response, gives me some things to think about/experiment with. This was actually one of the methods I originally tried, but could never get it to refresh properly. However, there seems to be some odd functionality with this. It seems to only work when the word doc is open on my computer when the code is ran. If the word doc it closed, the clone/re-name works, but it doesn't refresh.
    – George P.
    Sep 15 at 12:49
  • Ahh... good point I obviously had the word document open whilst I was testing it... ;) I will see if I can replicate the same issue.
    – Hornbydd
    Sep 15 at 12:56
  • Dam it you are right the code works with the word document open; could you bulk open the word documents prior to opening up ArcMap, that's a fudge I know but may be that's all that is required?
    – Hornbydd
    Sep 15 at 13:03
  • Yeah, that's what I'm testing variations of at the moment. Now that I know there is at least a condition for refreshing with arcpy, I think its just a matter of finding if there is an order of operations that will make it all work efficiently.
    – George P.
    Sep 15 at 13:07

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.