Select to view content in your preferred language

Script or code to plot file path & name, time, and date

7921
14
10-09-2010 06:19 AM
PhilLampe
Occasional Contributor
Hello,

I am running ArcGIS (ArcView license) 9.3.1 right now, but will eventually migrate over to 10 over the next few months.

I would like to add some form of automation to the MXD so that every time I print it will print out the map the file path/name, time, and date.

I found some code from the old forum site below.

http://forums.esri.com/Thread.asp?c=93&f=989&t=261743&mc=6

Code for the above link is below:
----------------------------------------------------------
Public Sub AddFilePath()

Dim pApplication As Application
Dim pDocument As IDocument
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayout As IPageLayout
Dim pActiveView As IActiveView
Dim pGraphicsCont As IGraphicsContainer
Dim pElement As IElement
Dim pElementProp As IElementProperties
Dim pTextElement As ITextElement

Set pApplication = Application
Set pDocument = pApplication.Document
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.Maps.Item(0) 'must be the first Data Frame in the map
Set pLayout = pMxDoc.PageLayout
Set pActiveView = pMxDoc.ActiveView

'Scroll through all elements on the layout
Set pGraphicsCont = pActiveView.GraphicsContainer
pGraphicsCont.Reset
Set pElement = pGraphicsCont.Next
Do Until pElement Is Nothing
  
  'Check the element's name - we are looking for one called "FileName"
  Set pElementProp = pElement
  If pElementProp.Name = "FileName" Then
  
    'Double-check that this is a text element
    If TypeOf pElement Is ITextElement Then
    
      'Update the text to the file path of the project
      Set pTextElement = pElement
      pTextElement.Text = pDocument.VBProject.FileName & " Last updated " & Now
      
    End If
  End If
  
  'Move on to the next graphic element
  Set pElement = pGraphicsCont.Next
Loop

'Refresh the display
pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing

End Sub

-------------------------------------------

Below I am giving you my questions AND what I changes I'd like to integrate into the above code to make it a little more applicable for my situation.

Here are my questions:


  1. I was wondering if anyone has any input on improving (if even necessary) the code shown above or has any other suggestions or ideas to accomplish this task.


  2. Will the above code work with 10?

Here are my desired modifications:

  1. I would like to have the stamp look this way:

  2. Map Plotted: 10-08-10 15:50, Map Edited: 10-08-10 15:49, File: C:\Maps\Client\Map.mxd
  3. Where: The Map Plotted date is the current date and time (in 24hr format) entity

  4. Where: The Map Edited date is the last modified date and time (in 24hr format) entity

  5. Where: The File is the file path and file name entity


TIA for your replies.
0 Kudos
14 Replies
PhilLampe
Occasional Contributor
Worked like a charm!

Thanks for taking the time out of your busy schedule to do this also.

I think this is going to be one my top 3 MUST HAVE scripts for all time.

Have a great day!
0 Kudos
MichaelWalden
Emerging Contributor
Can "Author" be scripted in from Document Properties?  Ultimately I would like the Author and Printed By (i.e. windows user who is printing the map) added to the script.
0 Kudos
nimitz
by
Regular Contributor
Hi all,
I was wondering if anyone knows if the .mxd files that are in ver9.3 will have any problem when people print them out?

TIA
0 Kudos
CorrieFochler
Deactivated User
Phil,

Long time no hear from, here you go.

First inside ArcMap

1. Inset --> Text
2. Right click the new text element --> Properties
3. Under Size and Position Tab
4. Element Name Should be : FileName

Next Inside Microsoft Visual Basic Editor

1. Tools --> References --> Check "Microsoft Scripting Runtime"
2. Inside Project --> ArcMap Objects --> ThisDocument
3. Paste Code Below and reference AddFilePath in your code that is already written.

Code To Paste:

Public Sub AddFilePath()



It has been about 5 years since I have had to use any VB customized code and have forgotten much of it thanks to arcgis 10. I am working with 9.3 now and need to add this file path to a construction drawing set.
Forgive my brain..... but where else do I reference the AddFilePath in your code that is already written.

I ran this and it didn't do anything, so I am sure I have forgotten how to call this funtion. 😞
0 Kudos
CorrieFochler
Deactivated User
It has been about 5 years since I have had to use any VB customized code and have forgotten much of it thanks to arcgis 10. I am working with 9.3 now and need to add this file path to a construction drawing set.
Forgive my brain..... but where else do I reference the AddFilePath in your code that is already written.

I ran this and it didn't do anything, so I am sure I have forgotten how to call this funtion. 😞


Nevermind I had breaks on.....
I worked great. Thanks so much for making my life easier.
0 Kudos