Select to view content in your preferred language

date stamp in arcgis 10

984
6
10-04-2010 05:24 AM
FrankVignati
Frequent Contributor
In our 9.3.1 MXDs we use a VBA function stored in the ThisDocument of the MXD to date stamp the maps as they are opened. Does anyone know if this will work in ArcGIS10 or if not what we can use to perform the same type of function?
This is what we currently use:

Option Explicit
Private WithEvents m_pActiveViewEvents As Map

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
             (ByVal lpBuffer As String, nSize As Long) As Long

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


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 UCase(Mid(pTextElement.Text, 1, 5)) = "DATE:" Then
                pTextElement.Text = "DATE: " & Date
            End If
        End If
        Set pElement = pGC.Next
    Loop
   
End Sub

Function UserName() As String
    Dim UN As String * 260
    GetUserName UN, Len(UN)
    UserName = UN
End Function
0 Kudos
6 Replies
FrankVignati
Frequent Contributor
never mind, i was told that in 10 there will be dynamic text that can be added to MXDs to handle this
0 Kudos
JakubSisak
Honored Contributor
never mind, i was told that in 10 there will be dynamic text that can be added to MXDs to handle this

Yes. A very nice feature indeed. Right under the Insert Menu -> Insert Dynamic Text
Read posts about version 10 before migrating... I jumped the gun now i wish I waited. VBA for example is being phased out which is most evident by the fact that in version 10 you can no longer add UI Controls (buttons, tools, etc) in the Normal Template only on document level.
0 Kudos
FrankVignati
Frequent Contributor
Yes. A very nice feature indeed. Right under the Insert Menu -> Insert Dynamic Text
Read posts about version 10 before migrating... I jumped the gun now i wish I waited. VBA for example is being phased out which is most evident by the fact that in version 10 you can no longer add UI Controls (buttons, tools, etc) in the Normal Template only on document level.


we heard that, time to learn python i guess, have you been able toadd ui type buttons with python?
0 Kudos
EricMartinson
Occasional Contributor
Yes. A very nice feature indeed. Right under the Insert Menu -> Insert Dynamic Text
Read posts about version 10 before migrating... I jumped the gun now i wish I waited. VBA for example is being phased out which is most evident by the fact that in version 10 you can no longer add UI Controls (buttons, tools, etc) in the Normal Template only on document level.

Somewhat useful for a one-off, but nothing compared to the utility of having a time/date/path signature box of the size and location you determine and that you can update at the click of a button.
This button control was a big help before we "upgraded" to Arc 10: http://arcscripts.esri.com/details.asp?dbid=12887
--Eric
0 Kudos
maxsteinbrenner
Emerging Contributor
i am a little confused are you just looking for code to pring the current date in .NET?

you can pull what you need from here:
      'Add Date
        pPoint = New Point

        If strLayoutType = "Landscape" Then
            pPoint.PutCoords(10.35, 0.25)
        Else
            pPoint.PutCoords(7.85, 0.25)
        End If

        pAV = pMxDoc.PageLayout
        pTextElement = New TextElement
        pElement = pTextElement
        pElement.Geometry = pPoint

        Dim strDate As String = DateTime.Now.Month.ToString & "/" & DateTime.Now.Day.ToString & "/" & DateTime.Now.Year.ToString

        myFont.Name = "Arial"
        myFont.Size = 6
        myTextSymbol.Font = myFont
        myTextSymbol.HorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHALeft
        pTextElement.Text = strDate
        pTextElement.Symbol = myTextSymbol
        AddElement(pTextElement, pPoint, "Date")


do you still want to use VBA in 10? here is my same basic code that works in VBA in 10:

'Add Date
    Set pPoint = New Point

    If strLayoutType = "Landscape" Then
        pPoint.PutCoords 9.9, 0.3
    Else
        pPoint.PutCoords 7.4, 0.3
    End If

    Set pAV = pMxDoc.PageLayout
    Set pTextElement = New TextElement
    Set pElement = pTextElement
    pElement.Geometry = pPoint

    strDate = Date

    myFont.Name = "Arial"
    myFont.size = 12
    myTextSymbol.Font = myFont
    myTextSymbol.HorizontalAlignment = esriTHALeft

    pTextElement.Text = strDate
    pTextElement.Symbol = myTextSymbol
    AddElement pTextElement, pPoint, "Date"


so what you are using should work. hope that helps...
0 Kudos
EricMartinson
Occasional Contributor
Hi Max-
Thanks for the code, but I'm afraid I'm a bit unschooled in how to use it. I'm guessing that if I knew .NET and VBA better, I could use your code to achieve what I used to with an ArcScript posted by a benevolent user years ago. His script made it easy for even lower primates such as me to add a button to an ArcMap toolbar that creates or updates a time/date/filepath stamp in the layout:
http://arcscripts.esri.com/details.asp?dbid=12887
The post has a link to download a txt with the code and instructions if you're curious.
Thanks again for any pointers you can give me.
Eric
0 Kudos