Article View: adobe.scripting.indesign
Article #16242Re: Group unlocked objects
From: Olav_Kvern
Date: Fri, 03 Oct 2003 18:51
Date: Fri, 03 Oct 2003 18:51
49 lines
2682 bytes
2682 bytes
Matthew--
Here's how to create a group when you know the number of objects you want to add (as you do in the case of a selection):
Dim myInDesign As InDesign.Application
Set myInDesign = CreateObject("InDesign.Application.2.0")
Rem The following assumes that two or more objects are selected.
Set mySelection = myInDesign.Selection
Rem Get the page containing the first object in the selection.
Set myPage = mySelection.Item(1).Parent
Rem The Groups.Add method wants an array, not an Objects collection,
Rem So read the objects out of the selection and into an array.
ReDim myArray(mySelection.Count - 1)
For myCounter = 0 To mySelection.Count - 1
Set myArray(myCounter) = mySelection.Item(myCounter + 1)
Next
Rem Groups.Add takes an optional parameter--target layer--first.
Rem To omit this parameter, add a comma, as I have in the following line:
Set myGroup = myPage.Groups.Add(, myArray)
Here's how to create a dynamic array (when you don't know how many objects you have:
Dim myInDesign As InDesign.Application
Set myInDesign = CreateObject("InDesign.Application.2.0")
Set mySpread = myInDesign.ActiveWindow.ActiveSpread
Set myPageItems = mySpread.PageItems
ReDim myArray(0)
Rem The following loop adds all unlocked page items to the array.
For myCounter = 1 To myPageItems.Count
If myPageItems.Item(myCounter).Locked = False Then
Rem If the array already contains an item, add another item to the array.
If Not (IsEmpty(myArray(0))) Then
ReDim Preserve myArray(UBound(myArray) + 1)
End If
Rem Add the page item to the array.
Set myArray(UBound(myArray)) = myPageItems.Item(myCounter)
End If
Next
If UBound(myArray) > 0 Then
Set myGroup = mySpread.Groups.Add(, myArray)
End If
Regarding getting/setting the object location--are you copying from one document to another, or from page to page in a single document?
Thanks,
Ole
Technical Details
Message-ID:
<2ccd9701.2@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccd9701.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,f1825763304d2027 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-10-03 12:08:14 PST From: Olav_Kvern@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: Group unlocked objects Message-ID: <2ccd9701.2@webx.la2eafNXanI> Date: Fri, 3 Oct 2003 11:51:36 -0700 References: <2ccd9701.-1@webx.la2eafNXanI> Lines: 49 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit