Thursday, January 31, 2008

How to Add the Date and the time to an ArcGIS layout

ArcGIS does not have a built in feature to add date, time, filepath and filename to you ArcGIS drawings (as you can in AutoCAD). I find this very annoying. Thankfully, you can find easy tutorials on how to program your own button to do this task at:

http://arcscripts.esri.com/scripts.asp?eLang=&eProd=28&perPage=10&eQuery=date

Most professionals make sure that this filename is on every drawing. One thing you should note: the time stamp that this program produces is not dynamic. ie. it is just static text.... it will not update automatically. If you come back to the drawing 3 weeks later, it will still have the old date and filepath. You need to use the button everytime you publish/print your ArcGIS mxd document.

Option 2: If you are ready to dive right in to VBA (alt+f11)

Option Explicit

Private WithEvents m_pActiveViewEvents As Map
Private Function MxDocument_BeforeCloseDocument() As Boolean
UnSetEvents
End Function

Private Function MxDocument_OpenDocument() As Boolean
SetEvents
End Function

Public Sub SetEvents()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Set m_pActiveViewEvents = pMxDoc.PageLayout
End Sub

Public Sub UnSetEvents()
Set m_pActiveViewEvents = Nothing
End Sub

' add time and by whom map printed
' date/time changes when layout refreshed -- you usually have to actually refresh it yourself to get the time to change correctly
' add a textbox that says something like pTextElement.Text below

Private Sub m_pActiveViewEvents_ViewRefreshed(ByVal pView As IActiveView, _
ByVal phase As esriViewDrawPhase, _
ByVal data As Variant, _
ByVal Envelope As IEnvelope)

Dim pGC As IGraphicsContainer
Set pGC = pView
pGC.Reset
Dim pElement As IElement
Set pElement = pGC.Next
Do While Not pElement Is Nothing
If TypeOf pElement Is ITextElement Then
Dim pTextElement As ITextElement
Set pTextElement = pElement
If Mid(pTextElement.Text, 1, 8) = "Printed:" Then ' look for the textelement to be refreshed
pTextElement.Text = "Printed: " & Format(Time, "h:nn AM/PM") & " on " & Format(Date, "mm/dd/yyyy") & " by Chuck Norris" '& _
'vbNewLine & put whatever else you want here on a new line - uncomment line continuer on above line at end too ...
End If
End If
Set pElement = pGC.Next
Loop

End Sub




Other Tags: Adding date/time to MXD documents, Adding filenames to MXD documents, making a button to add date/time to ArcGIS