🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18900

Re: ------ Date Stamp

#18900
From: Olav Kvern
Date: Thu, 30 Jan 2003 23:05
91 lines
4779 bytes
Bill--

We can't monitor the "save" event and automatically run a script each time, but we can easily have a script update a text frame with the current date and time and then save the file.

The following VBScript creates a text frame on the pages of the first master spread in the current document, then enters the date and time in the text frame. You'll have to set the text frame to printing/nonprinting yourself, as that feature is not supported (yet!) by InDesign scripting. You can adjust the positioning of the text frame using the settings in the "Options" section, and you can change the appearance of the text by editing the style "myDateStyle".



Rem DateTimeStamp 
Rem An InDesign VBScript 
Rem Inserts the current date and time into a 
Rem text frame marked with a specific tag. 
Rem Set the InDesign constant for points to its decimal value (comment out this line if you're using Visual Basic) 
idMSPoints = 2054188905 
Rem ---------- Options ---------- 
Rem Enter a width and height for the text frame 
myFrameWidth = 288 
myFrameHeight = 12 
Rem Set a position of the left edge of the frame (measured from the left edge of the page). 
myFrameX = 24 
Rem If you want InDesign to save the document after updating the date stamp, set mySave to True in the following line. 
mySave = False 
Rem -- End of options section --- 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.ActiveDocument 
Rem Get the date/time stamp paragraph style. 
On Error Resume Next 
Err.Clear 
Set myDateStyle = myDocument.ParaStyles.Item("myDateStyle") 
If Err.Number <> 0 Then 
    Rem Style did not exist, so create it. 
    Set myDateStyle = myDocument.ParaStyles.Add 
    myDateStyle.Name = "myDateStyle" 
End If 
Rem Reinstate normal error trapping. 
On Error Goto 0 
myPageHeight = myDocument.DocumentPreferences.PageHeight 
Rem Save the current measurement units. 
myOldXUnits = myDocument.ViewPreferences.HorzMeasurementUnits 
myOldYUnits = myDocument.ViewPreferences.VertMeasurementUnits 
Rem Change the measurement units to points. 
myDocument.ViewPreferences.HorzMeasurementUnits = idMSPoints 
myDocument.ViewPreferences.VertMeasurementUnits = idMSPoints 
Rem Get the date and time. 
Rem If you're using Visual Basic, use the following: 
'myDate = Date 
'myTime = Time 
Rem Format the Date/Time string. 
'myDateString = Format(myDate, "dddd, mmmm d, yyyy") & " " & myTime 
Rem If you're using VBScript, use the following: 
myDateString = FormatDateTime(Date, 1) & " " & Time 
Set myMasterSpread = myDocument.MasterSpreads.Item(1) 
For myCounter = 1 To myMasterSpread.Pages.Count 
    Set myMasterPage = myMasterSpread.Pages.Item(myCounter) 
    Err.Clear 
    On Error Resume Next 
    Set myTextFrame = myMasterPage.TextFrames.Item("myDateFrame") 
    If Err.Number <> 0 Then 
        Rem the text frame was not found, so create it. 
        Set myTextFrame = myMasterPage.TextFrames.Add 
        myTextFrame.Move , Array(myFrameX, myPageHeight - myFrameHeight) 
        myBounds = myTextFrame.GeometricBounds 
        myTextFrame.GeometricBounds = Array(myBounds(0) - myFrameHeight, myBounds(1), myBounds(0), myBounds(1) + myFrameWidth) 
        Rem Enter the date string in the text frame. 
        myTextFrame.TextContents = myDateString 
        Rem Mark the text frame with a label so that we can find it next time. 
        myTextFrame.Label = "myDateFrame" 
    Else 
        Rem We found the text frame, so simply update the date/time stamp. 
        myTextFrame.TextContents = myDateString 
    End If 
    Rem Apply the paragraph style. 
    myTextFrame.ParentStory.ParagraphStyle = myDateStyle 
    Rem Return to normal error trapping. 
    On Error Goto 0 
Next 
Rem Reset the measurement units to their original state. 
myDocument.ViewPreferences.HorzMeasurementUnits = myOldXUnits 
myDocument.ViewPreferences.VertMeasurementUnits = myOldYUnits 
If mySave = True Then 
    myDocument.Save 
End If 




Let me know if this works for you!

Thanks,

Ole
Technical Details
Message-ID: <1de798a2.0@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de798a2.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,9fc400afa096faf5
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-01-30 15:07:51 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: ------ Date Stamp
Message-ID: <1de798a2.0@WebX.la2eafNXanI>
Date: Thu, 30 Jan 2003 15:05:42 -0800
References: <1de798a2.-1@WebX.la2eafNXanI>
Lines: 102
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit