4 Replies Latest reply on Jul 28, 2016 2:29 PM by lan.mine

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

    lan.mine Level 1

      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.

        • 1. Re: Script to find all <Clip Group> and Run an Action to Crop
          Silly-V Adobe Community Professional

          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.

          • 2. Re: Script to find all <Clip Group> and Run an Action to Crop
            lan.mine Level 1

            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')

                    }

                };

             

            • 3. Re: Script to find all <Clip Group> and Run an Action to Crop
              Silly-V Adobe Community Professional

              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.

              • 4. Re: Script to find all <Clip Group> and Run an Action to Crop
                lan.mine Level 1

                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!