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

7388
14
10-09-2010 06:19 AM
PhilLampe
New Contributor III
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
ScottDavis
Occasional Contributor
You could try Dynamic Text once you have upgraded to version 10. It works very well.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/What_is_dynamic_text/00s90000000v00000...
0 Kudos
PhilLampe
New Contributor III
Scott,

Thanks for your reply.

Yes, I'm aware of that feature.  Do you know if that is also available at the ArcView license level?

Thanks,
Phil
0 Kudos
ScottDavis
Occasional Contributor
I just tested it with ArcView and it worked fine.
0 Kudos
PhilLampe
New Contributor III
Just so I'm understanding you correctly, you tested the Dynamic Text feature with ArcView, right?
0 Kudos
JeffMoulds
Esri Contributor
Just so I'm understanding you correctly, you tested the Dynamic Text feature with ArcView, right?


Dynamic Text is available with an ArcView license at 10.
0 Kudos
KenCarrier
Occasional Contributor III
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()

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

                'Date Last Modified
                'Make Sure You Reference Microsoft Scripting Runtime or this will not work!!!!!!
                Dim fso As New FileSystemObject
                Dim f As File
                Dim MapDocumentPath As String
                MapDocumentPath = pDocument.VBProject.FileName

                'Update the text to the file path of the project
                Set pTextElement = pElement
               
                Set f = fso.GetFile(MapDocumentPath)
                Dim filedate As String
                filedate = f.DateLastModified
                'MsgBox filedate
               
                pTextElement.Text = "Map Plotted: " & Now & ", " & "Map Edited: " & filedate & ", " & "File: " & MapDocumentPath

            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


Notes:

The plotted date is the current date and time, the map edited represents when the file was last modified or saved. the file is the full path to your document. Hope this helps let me know if you have any trouble, you have my email.
0 Kudos
ScottDavis
Occasional Contributor
Just so I'm understanding you correctly, you tested the Dynamic Text feature with ArcView, right?


That's correct.
0 Kudos
PhilLampe
New Contributor III
Hi Ken,

Looks like that did the trick!

THANKS for your help and THANKS to all who replied to my OP.

Phil.
0 Kudos
KenCarrier
Occasional Contributor III
Phil per our discussion, when you were doing a "save as", the document path would not reflect the new location of the mxd. You found this post "http://forums.esri.com/Thread.asp?c=93&f=993&t=116503" which has a better method for getting the document path which I have implemented into our existing code. Here is the new code which I think will accomplish what you are trying to do. You will still need to reference Microsoft Scripting Runtime to get the date modified.


Public Sub AddFilePath()

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

'Scroll through all elements on the layout
Dim pGraphicsCont As IGraphicsContainer
    Set pGraphicsCont = pActiveView.GraphicsContainer

    pGraphicsCont.Reset

Dim pElement As IElement
    Set pElement = pGraphicsCont.Next

Do Until pElement Is Nothing

    'Check the element's name - we are looking for one called "FileName"
    Dim pElementProp As IElementProperties
        Set pElementProp = pElement

            If pElementProp.Name = "FileName" Then

                'Double-check that this is a text element
                    If TypeOf pElement Is ITextElement Then

                        'Make Sure You Reference Microsoft Scripting Runtime or this will not work!!!!!!

                        Dim pTemplates As ITemplates
                            Set pTemplates = Application.Templates
                           
                        Dim lTempCount As Long
                            lTempCount = pTemplates.Count
                           
                        ' Normal is always the first item
                        Dim strNormalPath As String
                            strNormalPath = pTemplates.Item(0)
                           
                        ' The document is always the last item
                        Dim strDocPath As String
                            strDocPath = pTemplates.Item(lTempCount - 1)
                           
                        ' If present, the base template is the middle item
                        Dim strBasePath As String
                            If lTempCount = 3 Then
                                strBasePath = pTemplates.Item(1)
                            Else
                                strBasePath = "NO BASE TEMPLATE LOADED"
                            End If
                           
                        ' Report pathnames
                        ' MsgBox "Normal Template:  " & strNormalPath & vbNewLine & "Base Template:  " & strBasePath & vbNewLine & "Document:  " & strDocPath
                       
                        'Update the text to the file path of the project
                        Dim pTextElement As ITextElement
                            Set pTextElement = pElement
                           
                        Dim fso As New FileSystemObject
                        Dim f As File
                            Set f = fso.GetFile(strDocPath)
                           
                        Dim filedate As String
                            filedate = f.DateLastModified
                            'MsgBox filedate
                           
                            pTextElement.Text = "Map Plotted: " & Now & ", " & "Map Edited: " & filedate & ", " & "File: " & strDocPath
                           
                    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
0 Kudos