Article View: adobe.scripting.indesign
Article #18237Using 'AnyItem' to find a specific layer
From: Brian Boyce
Date: Thu, 10 Apr 2003 12:21
Date: Thu, 10 Apr 2003 12:21
107 lines
4676 bytes
4676 bytes
I'm trying to make a control panel in visual basic, and one of my commands is to create a border layer. What I'm having problems on is the syntax required to create an if/then statement to look for a previous "Border Layer". I don't know that much about visual basic, so I'm stuck on this one.
Here's what I have so far:
* **************************************
Private Sub CreateBorders_Click()
Rem This script will create borders for any composite template
Dim InD As Indesign.Application
Set InD = CreateObject("InDesign.Application.2.0")
Rem Check for an open document
If InD.Documents.Count = 0 Then
MsgBox "Please open a document and try again."
Else: GoTo OpenDocument
End If
Exit Sub
OpenDocument:
Set InDWindow = InD.ActiveWindow
Set InDSpread = InDWindow.ActiveSpread
Set InDDocument = InD.ActiveDocument
Set InDPage = InDDocument.Pages.Item(1)
Rem Set the units to inches
InD.ActiveDocument.ViewPreferences.HorzMeasurementUnits = idMSInches
InD.ActiveDocument.ViewPreferences.VertMeasurementUnits = idMSInches
Rem Get the margin preferences of page 1
InD1 = 1
InDH = 0.5
InDLM = InDPage.MarginPreferences.MarginLeft
InDTM = InDPage.MarginPreferences.MarginTop
InDRM = InDDocument.DocumentPreferences.PageWidth
InDBM = InDDocument.DocumentPreferences.PageHeight
InDRI = InDRM - InD1 - InDH
InDBI = InDBM - InD1 - InDH
InDLI = InDLM + InD1
InDTI = InDTM + InD1
InDRB = InDRM - InD1
InDBB = InDBM - InD1
InDLB = InDLM + InDH
InDTB = InDTM + InDH
Rem deletes the previous border layer
Rem This script reads all pageitems in the active document, then creates a new document and puts the results in a new textframe
Rem Open Indesign. The Adobe Indesign 2.0 Type Library should be referenced in this project
Rem Set myInDesign = CreateObject("InDesign.Application.2.0")
Rem Find the current path
Rem Str_CurrentPath = VB.App.Path
Rem Read all from the active document
Rem Dim myDocument As Indesign.Document
Rem Set myDocument = myInDesign.ActiveDocument
Rem Loop through all pages
For Counter = 1 To InDDocument.Pages.Count
Set InDPageCounter = InDDocument.Pages.Item(Counter)
Rem look for pageitems on this page
For Each PageItem In InDPageCounter.PageItems
Rem Put the ID and the scriptlabel in a string
Rem str_Pageitems = str_Pageitems & "PageItem ID: " & PageItem.ID & " Label: " & PageItem.Label & vbCrLf
Rem If Any.PageItem.Label = ("Border Layer") Then
If InDDocument.Objects.AnyItem(Layer) = InDDocument.Layers.Item("Border Layer") Then
Rem If InD.PageItem.Label("Border Layer") = 1 Then
Rem If InD.Document.Layers.Count.
Set InDBorderLayer = InDDocument.Layers.Item("Border Layer")
InDBorderLayer.Locked = 0
InDBorderLayer.Delete
Else: GoTo AddBorderLayer
End If
Next
Next
AddBorderLayer:
Rem Add the border layer
Set InDLayer = InDDocument.Layers.Add
InDLayer.Color = idUIGreen
InDLayer.Name = "Border Layer"
Rem Move the border layer to the bottom of the layers palette
InDLayer.Move (idAtEnd)
Rem Add a guide.
Set InDGuide = InDSpread.Guides.Add
InDGuide.GuideOrientation = idVertical
InDGuide.GuideColor = idUIBlue
InDGuide.GuideFitToPage = True
InDGuide.GuideLocation = InDLB
Rem Add a guide.
Set InDGuide = InDSpread.Guides.Add
InDGuide.GuideOrientation = idHorizontal
InDGuide.GuideColor = idUIBlue
InDGuide.GuideFitToPage = True
InDGuide.GuideLocation = InDTB
Rem Add a guide.
Set InDGuide = InDSpread.Guides.Add
InDGuide.GuideOrientation = idVertical
InDGuide.GuideColor = idUIBlue
InDGuide.GuideFitToPage = True
InDGuide.GuideLocation = InDRB
Rem Add a guide.
Set InDGuide = InDSpread.Guides.Add
InDGuide.GuideOrientation = idHorizontal
InDGuide.GuideColor = idUIBlue
InDGuide.GuideFitToPage = True
InDGuide.GuideLocation = InDBB
Rem Add a guide.
Set InDGuide = InDSpread.Guides.Add
InDGuide.GuideOrientation = idVertical
InDGuide.GuideColor = idUIGreen
InDGuide.GuideFitToPage = True
InDGuide.GuideLocation = InDRI
Rem Add a guide.
Set InDGuide = InDSpread
Technical Details
Message-ID:
<1de8adea.-1@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebXShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,ef1939a135b96319,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-04-10 05:38:03 PST From: "Brian Boyce" <promithius@hotmail.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Using 'AnyItem' to find a specific layer Message-ID: <1de8adea.-1@WebX.la2eafNXanI> Date: Thu, 10 Apr 2003 05:21:25 -0700 Lines: 115 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit