/* JET_ReplaceWithSymbolCenteredDK.js (formerly JET_ReplaceWithSymbol.jsx) (found on https://forums.adobe.com/message/4093796#4093796 and/or https://forums.adobe.com/thread/939631 ) A Javascript for Adobe Illustrator Purpose: Replaces selected items with Instances of a Symbol from the Symbols Panel. The desired Symbol can be defined by its index number (its number of occurrance in the Panel, with the first symbol being # 1). The new Symbol Instances get placed in the first/top Layer, which MUST BE UNLOCKED (and visible?). HEAVILY MODIFIED BY DK, JUNE 2015. MAIN CHANGES: --centers the Symbol on the graphic it is replacing (as best as possible) --does not resize the Symbol (uses the Symbol's "native" size) NOTE: According to my tests in Illustrator CC 2014 (see K:\trails\New 2015 Print Trail Maps\Illustrator\scripts\CoordinateTest.xlsx ): --Coordinates are in Points (pt) and appear to have their origin (0,0) at the lower left corner of the artboard --X coordinates increase as you go right (east); Y coordinates increase as you go up (north) --The various PageItem methods to get coordinates are quirky; some include the extent of any stroke the graphic might have, and some don't. --Methods that DO include the stroke's extent: .left, .top, .visibleBounds --Methods that DO NOT include the stroke's extent: .width, .height, .position, .geometricBounds */ var docRef=app.activeDocument; var symbolNum=prompt("Enter the number of the Symbol you want to replace each selected object",1); // first symbol = 1, etc. if (symbolNum) { for (i=0;i 0) { var chosenSymbol = docRef.symbols[symbolNum - 1]; // added by DK if (chosenSymbol) { var currInstance=docRef.symbolItems.add(chosenSymbol); // creates new Symbol Instance //currInstance.width*=currHeight/currInstance.height; // DK: we're not resizing the Symbol //currInstance.height=currHeight; // DK: we're not resizing the Symbol currInstance.left = currCenterX - (currInstance.width / 2); // added by DK - assumes Symbol .height is reliable/includes stroke currInstance.top = currCenterY + (currInstance.height / 2); // added by DK - assumes Symbol .height is reliable/includes stroke //alert("i = " + i + "; currLeft = " + currLeft + "; currTop = " + currTop + "; currWidth = " + currWidth + "; currHeight = " + currHeight + "; currCenterX = " + currCenterX + "; currCenterY = " + currCenterY + "; currInstance.left = " + currInstance.left + "; currInstance.top = " + currInstance.top); currInstance.selected=true; // select new Symbol Instance currObj.remove(); // delete old page item } else {alert("Symbol #" + symbolNum + " is not valid. Try a Symbol # between 1 and " + docRef.symbols.length);} } else {alert("Symbol #" + symbolNum + " is not valid. Try a Symbol # between 1 and " + docRef.symbols.length);} } else {alert(symbolNum + " is not a valid number. Try a Symbol # between 1 and " + docRef.symbols.length);} } redraw(); } else {alert("No symbol replacement occurred");}