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

Script to find all <Clip Group> and Run an Action to Crop

Explorer ,
Jul 27, 2016 Jul 27, 2016

Hello,

I am currently scripting for Illustrator CS6. I am fairly new to JavaScript. I was wondering if it is possible for a script to identify all <Clip Group> within the file and for it will run an Action to crop within pathfinder? I have created the Action to crop, but I am unsure as to how to call the action correctly for it to work. Any help on this is greatly appreciated.

TOPICS
Scripting
1.7K
Translate
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

Valorous Hero , Jul 28, 2016 Jul 28, 2016

It's a little complicated, but mostly because of the order of things, in addition to the basic syntax, etc.

#target illustrator

function test(){

  var doc = app.activeDocument;

  app.executeMenuCommand("Clipping Masks menu item");

  var thisClipItem;

  var esc = 50; // make sure to have an escape route for the while statement

  while(doc.selection.length != 0 && esc > 0){

    esc--;

    thisClipItem = doc.selection[0];

    doc.selection = null;

    thisClipItem.parent.selected = true;

    app.doScript("Crop

...
Translate
Adobe
Valorous Hero ,
Jul 27, 2016 Jul 27, 2016

Hello!

This may be a complicated thing to start out with, but here is how you can select all of the clipping mask objects automatically, after which you can cycle through the document.selection to find each one's parent group and then perform the cropping.

You select the clipping paths with:
app.executeMenuCommand("Clipping Masks menu item");

And, you run your action with:

app.doScript(actionName, setName);

Since the cropping procedure will require that you work on the groups individually, it would change your selection, so you'll have to deal with it however you see fit.

Translate
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 ,
Jul 28, 2016 Jul 28, 2016

HI Silly-V,

Thank you for answering my questions. This is what I have so far. The files that I am currently working with that have a clipping mask is labeled as <Clip Group>. Will I need to identify it somehow so the script below will work? Any examples will help me out a bunch. Thanks again.

#target illustrator

var clippingMask = app.executeMenuCommand("Clipping Masks menu item")

function cropMask(clippingMask){

    if(clippingMask.length>0){

        app.doScript('Cropify', 'Custom Art Actions')

        }

    };

Translate
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
Valorous Hero ,
Jul 28, 2016 Jul 28, 2016

It's a little complicated, but mostly because of the order of things, in addition to the basic syntax, etc.

#target illustrator

function test(){

  var doc = app.activeDocument;

  app.executeMenuCommand("Clipping Masks menu item");

  var thisClipItem;

  var esc = 50; // make sure to have an escape route for the while statement

  while(doc.selection.length != 0 && esc > 0){

    esc--;

    thisClipItem = doc.selection[0];

    doc.selection = null;

    thisClipItem.parent.selected = true;

    app.doScript("CropArt","CropArtSet");

    doc.selection = null;

    app.executeMenuCommand("Clipping Masks menu item");

  }

};

test();

You've got to keep the selection 'juggled' so that the right things are selected when you want them. In this case, we get all of the clipping masks using the selection command, but then in order to use the Crop, we have to deselect all but one of the clipping paths, select the parent group to get the clip and its art both, then use Crop and deselect the result, and then make sure to select the clipping paths again. The while loop is supposed to quit when we are no longer able to select any clipping paths, but in case things go wrong there's an esc variable- right now it's set to 50, make sure this number is larger than your expected clipping paths.

Translate
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 ,
Jul 28, 2016 Jul 28, 2016
LATEST

This makes so much more sense now. I wasn't aware just how complex something like this can be. Thank you so much for your help!

Translate
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