This has been a long standing wish of mine, and I've devised this script that "kind of" works.
This script takes your selection, copies appearance attributes, and pastes them to the top object after clipping.
It's currently limited in a few ways:
• It does not accept compound paths as clipping object (and I don't know how to test for it, nor how to iterate down said compound clipping object to set each path object to clipping separately)
• It only works with a single stroke or fill
• It does not understand "no fill" it will fill your object with white instead *FIXED*
• I'm hoping to use the "graphicStyle" property to copy the appearance, since that sounds way cleaner. But I don't understand how to.
Even with these limitations, I bound this to CMD+7 using fastscripts - I'm *already* used to it working this way!
Carlos Santos, thank you for writing the base of what became this script
I'd be much obliged if anyone can help me out with any of those limitations / wishes.
#target Illustrator // script.name = Clip Retaining Color.jsx; // script.required = at least two paths selected, top most path is the clipping mask; // script.parent = Herman van Boeijen, www.nimbling.com // 30/11/13; // *** LIMITED TO A SINGLE STROKE AND/OR FILL OF THE CLIPPING OBJECT*** // Here's hoping to use the "graphicStyles" property to copy over the appearance. if ( app.documents.length > 0 ) { idoc = app.activeDocument; }else{ Window.alert("You must open at least one document."); } var idoc = app.activeDocument; // get active document; var sel = idoc.selection; // get selection var selectedobjects = sel.length; function ClipRetainingColour(idoc){ var lay = activeDocument.activeLayer if(lay.locked || !lay.visible){ alert("Please select objects on an unlocked and visible layer,\nthen run this script again."); return; } var igroup = lay.groupItems.add(); // add a group that will be the clipping mask group var imask = sel[0]; // the mask is the object on top var clipcolors = []; //copy appearance if(imask.filled) {clipcolors.fillColor = imask.fillColor;} if(imask.stroked) { clipcolors.stroked = imask.stroked; clipcolors.strokeWidth = imask.strokeWidth; clipcolors.strokeColor = imask.strokeColor; } for (var i = selectedobjects-1 ; i > 0 ; i--){ var ipath = sel[i]; ipath.move(igroup, ElementPlacement.PLACEATBEGINNING); } imask.move (igroup, ElementPlacement.PLACEATBEGINNING); //enable clipping igroup.clipped = true; imask.clipping = true; //paste appearance if(clipcolors.fillColor) {imask.fillColor = clipcolors.fillColor;} if(clipcolors.stroked) { imask.stroked = clipcolors.stroked; imask.strokeWidth = clipcolors.strokeWidth; imask.strokeColor = clipcolors.strokeColor; } } if (selectedobjects){ ClipRetainingColour(idoc); }