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

Can you loop through items within Pattern Editing Mode?

Enthusiast ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

In looking through the Pattern Editing mode, I saw that Illustrator calls the mode a layer, and the first child a groupItem. Knowing that the structure in this mode is always Layer: Pattern Editing Mode > Group: "Name of Pattern" is there a way to loop through it's contents as it doesn't respond to groupItems[0]? I also tested app.activeDocument.layers["Pattern Editing Mode"].pluginItems[0], but it doesn't seem to contain anything useful. Second issue I have is with the scope of pageItems, which appears to be global if called at the document level, but once specifying a layer or group, it can only see the immediate children, is there a way to call this globally within a layer/group? Or does it have to be done through a recursive loop?

TOPICS
Scripting

Views

1.1K

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

correct answers 1 Correct answer

Enthusiast , Sep 10, 2018 Sep 10, 2018

I've found a way to infiltrate the Pattern Editing Mode structure through scripting. If someone has a more straight forward way to access this hierarchy, I'd be happy to hear it, but otherwise had to think outside the box on this one. Based on the prior discovery of being able to access child pageItems through selection[0].parent, I figured that selecting all to make sure there was a selection, may be too time consuming if the pattern was too complicated. Instead I created a decoy rectangle, ass

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

To your first question, I don't believe we have access to the pattern editor via javascript. =(

To your second question about scope, this is one of those things that i alternate between believing it's a feature or a bug. Because of the wild unpredictability, i never loop items at the document level, which inevitably leads me to the problem you described of how to reliably access all of the nested children in a specified scope. fortunately (or unfortunately, depending on how you look at it) there is a somewhat straightforward method of doing so... And as you surmised, it's recursion. I've written several different recursive functions for different scripts for the purpose of traversing a specific tree, but i've never invested the time to write a nice universal, portable version. Perhaps i'll do that as soon as i get some free time and I'll share it here.

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 ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

actually it does appear you have access to some properties for the PatternColor object. it's in the documentation and the OMV. Though I don't know what changes you need to make.. It sounds like the properties here are not what you were looking for.

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
Enthusiast ,
Sep 08, 2018 Sep 08, 2018

Copy link to clipboard

Copied

Agreed calling loops from the document level probably isn't the best, but it's pretty convenient with how greedy it can be! I guess pattern editing mode is similar to symbol editing mode and isolation mode, where you're almost in a parallel Illustrator universe. Running a recursive function that's pointed at the document, did toss an error for the layer I had in isolation mode, when my script tried to delete it but couldn't possibly because of the mode I was in.

If you find recursion straight forward, you are a true wizard. 🙂 The main challenge I'm facing with relative recursion, is what order to process in. I am looping from highest to lowest to prevent reference errors but then comes the chaos that is the order of operations, although calling locally would avoid some of the possibility of looping through a path/group within compound path without intending to. It can get a little confusing where to call certain events in order to be sure that layers are getting traversed, and ignored if intended.

For Isolation Mode app.activeDocument.layers[0] seems to be the top level, and for Symbol Editing app.activeDocument.layers[0].layers[0] and accessing the name will help to confirm where to begin with the recursion. For pattern editing, I can get the name from app.activeDocument.layers[0].pluginItems[0] or app.activeDocument.layers[0].pageItems[0] but trying to access any children below that through pageItems, groupItems etc doesn't seem to work. I am however able to access these through app.activeDocument.selection[0].parent, but that doesn't seem stable?

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
Enthusiast ,
Sep 10, 2018 Sep 10, 2018

Copy link to clipboard

Copied

LATEST

I've found a way to infiltrate the Pattern Editing Mode structure through scripting. If someone has a more straight forward way to access this hierarchy, I'd be happy to hear it, but otherwise had to think outside the box on this one. Based on the prior discovery of being able to access child pageItems through selection[0].parent, I figured that selecting all to make sure there was a selection, may be too time consuming if the pattern was too complicated. Instead I created a decoy rectangle, assigned the parent to a variable, and deleted the decoy now that I had access to the parent object. Probably not the safest route since it assumes a lot, primarily that Illustrator will organize things correctly, but it works!

aD = app.activeDocument;

var structureSpy = aD.pathItems.rectangle(200,200,200,200);

var noC = new NoColor();

structureSpy.name = "Structure Spy";

structureSpy.strokeColor = noC;

structureSpy.fillColor = noC;

redraw(); //Forces the new path into the mysterious "Pattern Editor Object" otherwise it's created and accessed via script at the Pattern Editing Mode level

//NOTE: Deleting the name of Pattern Group so it renames with "Pattern Editor Object" and running again will cause a duplicate Pattern editing object nested within that Illustrator will warn and expand when saving

var structureParent = structureSpy.parent;

structureSpy.remove();

redraw(); //Update so the spy is mere history

for(var i = 0; i<structureParent.pageItems.length; i++){

  alert(structureParent.pageItems.name); 

}

Additionally, identifying what editing mode you're in doesn't seem to be have a 100% foolproof method, but I've identified the following specific tests that could be could be shortened if needed. Primarily I kept adding on to the if statement conditions, since simply basing it off of a single layer name that could be replicated in the document seemed less preferable.

aD = app.activeDocument;

var modeName = aD.layers[0].name;

var lyr1Name = aD.layers[1].name;

if(modeName == "Isolation Mode"  && (lyr1Name == "Non Editable Art" && aD.layers[1].opacity == 50 && aD.layers[1].locked == true)) alert("You're probably in Isolation Mode");

if(modeName == "Symbol Editing Mode" && (lyr1Name == "Non Editable Art" && aD.layers[1].opacity == 50 && aD.layers[1].locked == true)) alert("You're probably In Symbol Editing Mode");

if(modeName == "Pattern Editing Mode" && (lyr1Name == "Non Editable Art" && aD.layers[1].opacity == 100 && aD.layers[1].locked == true)) alert("You're probably In Pattern Editing Mode");

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