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

Swap symbol by another one

Engaged ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

Hi everybody,

my think goes to JET and his script:

#target illustrator
/*
JET_ReplaceWithSymbol.jsx
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).

To Use:
Document must have at least one Symbol defined.
Select objects. Run the script.
*/

var docRef=app.activeDocument;
var symbolNum=prompt("Enter the number of the Symbol you want to replace each selected object",1);
for(i=0;i<docRef.selection.length;i++){
    var currObj=docRef.selection;
    var currLeft=currObj.left;
    var currTop=currObj.top;
    var currWidth=currObj.width;
    var currHeight=currObj.height;
    var currInstance=docRef.symbolItems.add(docRef.symbols[symbolNum-1]);
    currInstance.width*=currHeight/currInstance.height;
    currInstance.height=currHeight;
    currInstance.left=currLeft;
    currInstance.top=currTop;
    currInstance.selected=true;
    currObj.remove();
    redraw();
}

So.. this script works fine but, in fact i need that symbols keep same layer, same order and same name of previous.

Is there a simple method to swap symbol item by another one ? or need i to rename created layer (delete previous) and move it in correct order ?

Thanks in advance, art.chrome

(i don't know, but i'm trying )

TOPICS
Scripting

Views

1.7K

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

Guide , Apr 09, 2010 Apr 09, 2010

Try add this line…

currInstance.move(currObj, ElementPlacement.PLACEBEFORE);

before this line…

currInstance.selected=true;

Votes

Translate

Translate
Adobe
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

Try add this line…

currInstance.move(currObj, ElementPlacement.PLACEBEFORE);

before this line…

currInstance.selected=true;

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
Engaged ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

Woohh,

Many thanks Muppet Mark simply and effective !

(and special thanks JET)

Regards, art.chrome

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
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

I have many a JET script too…

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
LEGEND ,
Dec 23, 2020 Dec 23, 2020

Copy link to clipboard

Copied

LATEST

Here is a small variation on JET's original script.

Changes:

  • Symbol Instance name is retained
  • Replacement Symbol centers horizontally on the original Symbol
  • Function argrument accepts the Symbol "Name" for easier automation

 

 

function swapSymbols(symbolName) {
    var aDoc = app.activeDocument;
    for (i = 0; i < aDoc.selection.length; i++) {
        var currObj = aDoc.selection[i];
        var currName = currObj.name;
        var currLeft = currObj.left;
        var currTop = currObj.top;
        var currWidth = currObj.width;
        var currHeight = currObj.height;
        var currInstance = aDoc.symbolItems.add(aDoc.symbols[symbolName]);
        currInstance.width *= currHeight / currInstance.height;
        currInstance.height = currHeight;
        currInstance.left = currLeft - (currInstance.width - currWidth/2) + (currInstance.width/2);
        currInstance.top = currTop;
        currInstance.name = currName;
        currInstance.selected = true;
        currObj.remove();
        redraw();
    }
}

 

 

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