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

Create a group of all items with scripting

Contributor ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

4.6K

Translate

Translate

Report

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
Adobe
Community Expert ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Contributor ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Mar 19, 2020 Mar 19, 2020

Copy link to clipboard

Copied

if(app.activeDocument.selection.length)
{
    app.executeMenuCommand("group");
}
else
{
    alert("Please select some items first.");
}

Votes

Translate

Translate

Report

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
Guide ,
Mar 19, 2020 Mar 19, 2020

Copy link to clipboard

Copied

 

 

//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);

 

 

 

 

 

Votes

Translate

Translate

Report

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 ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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
Guide ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

moveToEnd and moveToBeginning(document/layer/groupItem/compoundPathItem) appear to be legacy functions from Illustrator 10. I wonder if they were meant to be deprecated and replaced by move(). I find them more intuitive than move() with its two arguments and they still work. Unfortunately, I can't find the Illustrator 10 JS documentation.  

Votes

Translate

Translate

Report

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 ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

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:

ExtendScriptError.png

 

Thank you so much!

Votes

Translate

Translate

Report

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
Guide ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Jun 06, 2023 Jun 06, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

Thank you so much! This solved my problem!

Votes

Translate

Translate

Report

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