Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

VBScript Working with layers

New Here ,
Apr 08, 2009 Apr 08, 2009

Hello everybody!

I would like to use a script to work whith layers in InDesign CS3 but I can't find any reference for VBS.

The only one I have is "Set myLayer = myDocument.Layers.Add" to add a new layer. But, how to delete one or import one from another file, i.e. ?

Who can help me? Many thanks in advance!

Eliane

TOPICS
Scripting
4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2009 Apr 08, 2009

Yes, documentation for the latest versions would be nice. For now, see the Layer Methods in the InDesign Scripting Guide for CS2 and  a separate document abourt changes in CS3 (nothing to do with Layers, but a must-read).

http://www.adobe.com/products/indesign/pdfs/InDesign_Scripting_Guide.pdf

http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/indesign_cs3_scripting_rea...

You could use an Object Browser that shows all available properties and methods (already shown in earlier posts):

http://www.teusdejong.nl/indesign/IDBrowser.zip

There is no import method for layers. To copy a layer from another document, I use a simple method. The script tells to open both target and source document, turn on 'remember layers when copying', make only layers to copy visible. Cycle through all speads with the following: go to source doc/spread, selectall objects, copy, paste in place to target doc/spread.

Tony

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2009 Apr 08, 2009

Thanks for the links!

I already found a scripting documentation for CS3 under http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/InDesignCS3_ScriptingGuide... but it's not so complete.

Furthermore in Introduction to scripting (http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/Adobe_Intro_to_Scripting1....) there is an explanation how to view the VBS object library in any Microsoft Office Application. But the Object Browser you mentioned may be more convinient to use.

Well, I now have some to study and will try to find out the correct syntax!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2009 Apr 08, 2009

With the correct tools it doesn't take too long to find what you are looking for. Finally, to delete a layer use: myDocument.ActiveLayer.Delete.

Tony, I will follow your tip for the "import" of a layer through the copy procedure. Many thanks for your quick help!!!

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2009 Apr 08, 2009

Please disregard this message (att. too large), see the next one.

Message was edited by: Tony Tuneson

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2009 Apr 08, 2009

You need the Scripting Reference, not only the Guide.

I can't find it anymore on the Net quickly, so I made link for you:

https://www.clickanad.com/download/InDesign_Script_Model.zip
Filesize: 7,31 MB. This file will be downloadable until Wednesday, 22 April 2009

Good luck

T

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2009 Apr 08, 2009

Hi Tony,

sorry, but I'm still working on the script to copy a layer from another document. I guess I'm almost done, but I still can't find the proper syntax to select all objects of the layer... Could you help me? Sorry, I'm quite new in wrinting scripts for InDesign!

Many thanks in advance.

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2009 Apr 08, 2009

This is what woked for me; I can see some things that I would do differently now, but it works.

It's in VB6, not too different from your VBS, I hope.

Sub CopyLayers(IDSource As InDesign.Document, IDTarget As InDesign.Document)
Dim i As Long
Dim j As Long
Dim PageName As String
Dim theLayoutWindow As InDesign.LayoutWindow
Dim mySpread As InDesign.Spread
Dim SelCounter As Long
Dim LayerFound As Boolean
Dim myLayer As InDesign.Layer
Dim itemCount As Long

For i = 0 To LayerList.ListCount - 1
    For j = 1 To IDSource.Layers.Count
        If LayerList.List(i) = IDSource.Layers.Item(j).Name Then
            IDSource.Layers.Item(j).Visible = LayerList.Selected(i)
            If LayerList.Selected(i) Then
                LayerFound = True
            End If
        End If
    Next j
Next i

myIndesign.ClipboardPreferences.PasteRemembersLayers = True

If Not LayerFound Then
    MsgBox "No Layer selected. Exiting."
    Exit Sub
End If

For j = 1 To IDTarget.Layers.Count
    IDTarget.Layers.Item(j).Visible = False
    DoEvents
    Sleep (50)
    DoEvents
Next j

For i = 0 To LayerList.ListCount - 1
    LayerFound = False
    For j = 1 To IDTarget.Layers.Count
        If LayerList.List(i) = IDTarget.Layers.Item(j).Name Then
            If LayerList.Selected(i) = True Then
                IDTarget.Layers.Item(j).Visible = True
                DoEvents
                Sleep (50)
                DoEvents
            End If
            LayerFound = True
        End If
    Next j
    If (Not LayerFound) And LayerList.Selected(i) Then
        Set myLayer = IDTarget.Layers.Add
        myLayer.Name = LayerList.List(i)
    End If
Next i

For i = IDSource.Spreads.Count To 1 Step -1
   
    DoEvents
    If CopyImagesBTN.Caption = "Start" Then
        MsgBox "User aborted."
        Exit For
    End If

    Set mySpread = IDSource.Spreads.Item(i)
   
    Set theLayoutWindow = myIndesign.LayoutWindows.Item(1)
    myIndesign.ActiveDocument = IDTarget
    ZoomTo IDTarget.Spreads.Item(i)
   
    myIndesign.ActiveDocument = IDSource
    ZoomTo IDSource.Spreads.Item(i)
   
    IDSource.Select InDesign.idSelectAll.idAll, idReplaceWith
   
    If IDSource.Selection.Count > 0 Then
        IDSource.Select InDesign.idSelectAll.idAll, idReplaceWith
       
        myIndesign.Copy
       
        myIndesign.ActiveDocument = IDTarget
       
        Set mySpread = IDTarget.Spreads.Item(i)
       
        IDTarget.Select idSelectAll.idAll, idReplaceWith
       
        For itemCount = IDTarget.Selection.Count To 1 Step -1
            IDTarget.Selection.Item(itemCount).Locked = False
            IDTarget.Selection.Item(itemCount).Delete
        Next itemCount
       
        myIndesign.PasteInPlace
        IDTarget.Select idNothingEnum.idNothing
    End If
Next i

End Sub

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2009 Apr 09, 2009

Hi Tony,

many thanks for your script! Unfortunately the VBScript syntax is slightly different from Visual Basic. I used to write in VBA for Microsoft Word and now started with VBScript, but I never wrote in Visual Basic. Since my script is almost finished and is a part of a bigger one, I would like to have it completely in VBScript.

The command I'm looking for corresponds to your "IDSource.Select InDesign.idSelectAll.idAll, idRepplaceWith". I think, the best thing is to post a new thread asking for the syntax to select all objects in VBScript (which I will do in a few minutes).

Again many thanks for your help!

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2009 Apr 09, 2009

Eliane_Yanou wrote:

many thanks for your script! Unfortunately the VBScript syntax is slightly different from Visual Basic. I used to write in VBA for Microsoft Word and now started with VBScript, but I never wrote in Visual Basic. Since my script is almost finished and is a part of a bigger one, I would like to have it completely in VBScript.

syntax is exactly the same the one difference I found is with For...To...Next - in VB6 (not VB.Net) you need to add variable name after Next - in VBS you should leave Next alone

robin

--

www.adobescripts.co.uk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2009 Apr 09, 2009

Hi Robin,

I also already found out that in VBS you should leave Next alone in the For...To...Next loop. But this is not the only thing as "select all object" didn't work neither... But we are discussing this point in another thread.

Anyhow, I will let you now when I find the solution!

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2009 Apr 09, 2009

Tony Tuneson wrote:

To copy a layer from another document, I use a simple method. The script tells to open both target and source document, turn on 'remember layers when copying', make only layers to copy visible. Cycle through all speads with the following: go to source doc/spread, selectall objects, copy, paste in place to target doc/spread.

but you will lose links between TextFrames in Story ...

robin

--

www.adobescripts.co.uk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2009 Apr 09, 2009

OK, I will have to check that when I will be finished with the first part...

Tanks!

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2009 Apr 09, 2009

you have nothing to check I'm not guessing

you will lose your threading - if Story is on different spreads

as workaround - you need to mark (by Label) all TextFrames in Story and recreate linked order

robin

www.adobescripts.co.uk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2009 Apr 09, 2009

OK, I must admit that I don't know InDesign very well since I'm not creating the documents myself...

What I meant is that I will have to check how the docs are made and will have to find a compromise depending on the structure of the documents.

But you gave me very valuables tips how to try to find a solution. Thanks!

Eliane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 09, 2009 Apr 09, 2009

That's a fact. If the doc is not too large, you could set all pages as a big spread first, and do one big select copy/paste.

Message was edited by: Tony Tuneson; removed "Or label the linked textframes and relink them after copying."

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2009 Jul 10, 2009

Hi,

I wan to count how many layers have in a indesign document.

What does the code to make this? I need in javascript. Could you help me please?

I write this code, but is not correct.

var n=app.activeWindow.Layers.count;

alert("Layers is " + n);

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 10, 2009 Jul 10, 2009
LATEST

var myDoc = app.activeDocument;
var myLayersCount = myDoc.layers.length;
var myMessage = (myLayersCount == 1)?"There is 1 layer in the document.":"There are " + myLayersCount + " layers in the document."
alert(myMessage);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines