Skip to main content
Inspiring
March 18, 2020
Question

Create a group of all items with scripting

  • March 18, 2020
  • 3 replies
  • 6644 views

Is there anyway to create a group of all my pathItems and then move that group?  Something like this.

var allPathItems = app.activeDocument.pathItems;

var myGroup = group add allPathItems

myGroup.left = 500

 

Obviously the above is not actual proper syntax but just an idea of what I want to do.  So I can easily move everything on a layer into a certain area.

This topic has been closed for replies.

3 replies

femkeblanco
Brainiac
March 19, 2020

 

 

//create group
var group = activeDocument.groupItems.add();
//add all path items to group
for (i = 0; i < activeDocument.pathItems.length; i++) {
  activeDocument.pathItems[i].moveToEnd(group);
}
//move group 50 mm to left
group.translate(-50*2.835, 0);

 

 

 

 

 

Karl Fabian5F97
Inspiring
January 15, 2021

Hello,

 

Thank you for this answer. I have a questions regarding the .moveToEnd function. I cannot find it in nor in the "Adobe Illustrator CC Scripting Reference: JavaScript" nor in the general Illustrator Scripting Guide. If I am not incorrect it is not part of the official documentation.

 

What does this mean? Is it part of some external library? I am wondering because it would be great to knwo fi there are more useful functions such as that one which can't be found under the documentation.

 

Thank you!

Disposition_Dev
Community Expert
June 6, 2023

Hello, thank you for the answer, that makes a lot of sense. I was wondering if perhaps you could help me with an issue related to this thread. I used your answer for adding a pathItem object to a groupItem object in a script, and it worked wonderfully, so thank you for that.

However, I now have a script where I want to group all elements into 3 distinct GroupItem elements, depending on their vertical location in the artboard (PDF file). I have tried running this code but I get this error, perhaps you know what I am doing wrong:

 

Thank you so much!


the variable docPI is set to the "collection" of pathItems. Collections are basically like "propietary" adobe arrays. theyre not really proprietary... thats not the right word. If youre familiar with strongly typed languages, collections are somewhat like "private functions" which just means you can't edit them directly like you could with a user defined array. To edit them, you need to use the available functions (like add(), remove(), etc).

 

That said, when you use moveToBeginning() or moveToEnd(), the argument you pass cant be a collection. It needs to be some kind of container object (eg, groupItem, layer, compoundPathItem, or document).

 

based on the little bit of code i can see, it looks like youre trying to move "g1" to the bottom of the layer order?

 

if so, you dont want the moveToEnd() method. what you want is zOrder. like this:

 

g1.zOrder(ZOrderMethod.SENDTOBACK)

 

let me know if youre looking for something else instead

Disposition_Dev
Community Expert
March 19, 2020
if(app.activeDocument.selection.length)
{
    app.executeMenuCommand("group");
}
else
{
    alert("Please select some items first.");
}
JJMack
Community Expert
March 18, 2020

You question makes not sense to me .  There are Layer Groups  Photoshop.s Layer sets and there are layer comps.  A Path can have many closed path items that combine in different modes. You can merge paths using paste path and merge shape layers. I do not know of any groups of paths in Photoshop other than the Path Palette.  Your statement "var myGroup = group add allPathItems"   does not look like a valid Photoshop DOM JavaScript statement to me.  What is  a you idea of your group object .left about is 500 some unit like percent, pixels or other and what is it relative to?  However, I have a lot to learn about Adobe Photoshop DOM and JavaScript I just hack at it.  

 

If it a new feature you want use Adobe Feedback site idea 

JJMack
OhmsGAuthor
Inspiring
March 18, 2020

@JJMack, hi thanks for your response.  This is question for Illustrator not Photoshop.  It's in the Illustrator section.

JJMack
Community Expert
March 18, 2020

You should use the Ai forum then its has its own scripting users over there illustrator.   I can believe a vector editor like Ai may have Path groups. I see thih thread has beemmovet overt to Ai forum now.

JJMack