0
How do I put rectangles in a group (JavaScript)?
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/td-p/1148363
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
Hello,
I have a JavaScript script that draws several graphics rectangles on a page. I would like to put them in a group, the same as I would manually with a selection and ctrl-G.
I have tried many, many approaches but am unable to do it. I would be grateful if someone could either post a code fragment or sketch an outline of what I should do.
Thanks much,
Bill
I have a JavaScript script that draws several graphics rectangles on a page. I would like to put them in a group, the same as I would manually with a selection and ctrl-G.
I have tried many, many approaches but am unable to do it. I would be grateful if someone could either post a code fragment or sketch an outline of what I should do.
Thanks much,
Bill
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148364#M369161
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
This groups all text frames on the first page of a document:
doc = app.activeDocument;
doc.pages[0].groups.add (doc.pages[0].textFrames);
Peter
doc = app.activeDocument;
doc.pages[0].groups.add (doc.pages[0].textFrames);
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148365#M369162
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Peter,
Thanks for your suggestion. I was able to get that far along in my work. However, I don't want to group ALL the rectangles on the page, only the ones that I create with my script. I obviously have the rectangle returned by rectangles.add() but I can't figure out how to go from that to a group.
Thanks,
Bill
Thanks for your suggestion. I was able to get that far along in my work. However, I don't want to group ALL the rectangles on the page, only the ones that I create with my script. I obviously have the rectangle returned by rectangles.add() but I can't figure out how to go from that to a group.
Thanks,
Bill
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148366#M369163
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Hi Bill,
If you're labeling the rectangles as you create them, then this should work:
myGroup = myPage.groups.add(myPage.rectangles.item("GroupMe"));
Dave
If you're labeling the rectangles as you create them, then this should work:
myGroup = myPage.groups.add(myPage.rectangles.item("GroupMe"));
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148367#M369164
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
You can also use an array. For example, say you had a mix of items that met various criteria, you could do something like this:
Dave
myPage = app.documents[0].pages[0];I've just used one criterion here, but you could have as many tests as you want within the loop.
groupies = new Array();
myPIs = myPage.pageItems;
for (var j = myPIs.length - 1; j >= 0; j--) {
if (myPIs.label == "GroupMe") {
groupies.push(myPIs);
}
}
myGroup = myPage.groups.add(groupies);
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148368#M369165
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Hi Dave,
Thanks, I'll give it a try.
Bill
> A new message was posted by Dave Saunders in
>
> *InDesign Scripting* --
> How do I put rectangles in a group (JavaScript)?
>
> Hi Bill,
>
> If you're labeling the rectangles as you create them, then this should
> work:
>
> myGroup = myPage.groups.add(myPage.rectangles.item("GroupMe"));
>
> Dave
Thanks, I'll give it a try.
Bill
> A new message was posted by Dave Saunders in
>
> *InDesign Scripting* --
> How do I put rectangles in a group (JavaScript)?
>
> Hi Bill,
>
> If you're labeling the rectangles as you create them, then this should
> work:
>
> myGroup = myPage.groups.add(myPage.rectangles.item("GroupMe"));
>
> Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148369#M369166
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Hi Dave,
Thanks much. Just one more thought... Is there some way to identify the index in pageItems or the specific pageItem of an newly created rectangle, that is, from the rectangle returned by rectangles.new()? I could then push that specific PI onto an array and after I make all the rectangles I could then make the group from the array of PIs as you did above.
Bill
Thanks much. Just one more thought... Is there some way to identify the index in pageItems or the specific pageItem of an newly created rectangle, that is, from the rectangle returned by rectangles.new()? I could then push that specific PI onto an array and after I make all the rectangles I could then make the group from the array of PIs as you did above.
Bill
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148370#M369167
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Sure:
myRect = myPage.rectangles.add();
myGroupies.push(myRect);
Dave
myRect = myPage.rectangles.add();
myGroupies.push(myRect);
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148371#M369168
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
That was the first thing that I tried and I'm quite sure that it didn't work. myPage.rectangles.add() returns a rectangle, not a pageItem. groups.add() expects an array of pageItems and was displeased when I called it with a list of rectangles. I'll try it again in the event that I had something screwed up.
Bill
Bill
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148372#M369169
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Rectangles are page items.
Page item is a generic kind of object; rectangles are specific kinds.
It is, though, possible to create an array of rectangles (or any page items) that can't be grouped. For example, if oone (or more) of the rectangles is already in a group or is anchored to text. Or if the objects are on different spreads.
The syntactic correctness of a parameter doesn't assure success.
Dave
Page item is a generic kind of object; rectangles are specific kinds.
It is, though, possible to create an array of rectangles (or any page items) that can't be grouped. For example, if oone (or more) of the rectangles is already in a group or is anchored to text. Or if the objects are on different spreads.
The syntactic correctness of a parameter doesn't assure success.
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148373#M369170
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Aha! Now that makes a lot of things clearer. Thanks! I'll give the array of my newly created rectangles another try. There was probably something else at play during my first test.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Bill_Wetzel_
AUTHOR
New Here
,
LATEST
/t5/indesign-discussions/how-do-i-put-rectangles-in-a-group-javascript/m-p/1148374#M369171
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
Dave & others,
After an afternoon of some frustration, mostly due to noobie issues:
1) The distinction between "Selection" vs. "Direct Selection" pointers.
2) That a group cannot contain just one item
I was finally able to accomplish exactly what I wanted. I push each rectangle onto an array as I make it. I then page.groups.add() that array of rectangles and then select the group. Works perfect.
My sincere thanks for your help. I really appreciate it. Lots to learn.
Bill
After an afternoon of some frustration, mostly due to noobie issues:
1) The distinction between "Selection" vs. "Direct Selection" pointers.
2) That a group cannot contain just one item
I was finally able to accomplish exactly what I wanted. I push each rectangle onto an array as I make it. I then page.groups.add() that array of rectangles and then select the group. Works perfect.
My sincere thanks for your help. I really appreciate it. Lots to learn.
Bill
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

