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

Illustrator script: all Artboard Elements to Symbol

New Here ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

Hi,

I have been trying to make a simple script that selects all elements on an artboard and makes a symbol with the name of the artboard. Unfortunately the symbols.add(selection) does not work. Can anyone give me a clue or solution. 

TOPICS
Scripting

Views

249

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
Adobe
Guide ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

One can't debug code that one can't see. Also, it would be helpful to show what you're trying to achieve with a screenshot. 

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
Community Expert ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

Hi,

You can try the following,

 

var doc = app.activeDocument;
var _activeAtboardName = doc.artboards[app.activeDocument.artboards.getActiveArtboardIndex()].name
doc.selectObjectsOnActiveArtboard();
app.executeMenuCommand('group');
var _symbol = doc.symbols.add(app.selection[0]);
_symbol.name = _activeAtboardName;
app.executeMenuCommand('ungroup');

 

app.selection, is an array, but symbols.add expect a single pageItem not an array, tehrefore, group all items before making symbol and after that ungroup it.

 

 

Best regards

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

@Charu Rajput , 
Your code example creates a symbol but does not replace the selection with the symbol. How do I convert the selection to a symbol?

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
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

@rcraighead ,

I don't know direct way to convert but below is the workaround, where I am placing newly created symbol at the same position where selection exist.

var doc = app.activeDocument;
var _activeAtboardName = doc.artboards[app.activeDocument.artboards.getActiveArtboardIndex()].name;
doc.selectObjectsOnActiveArtboard();
app.executeMenuCommand('group');
var _selectedItem = app.selection[0];
var _symbol = doc.symbols.add(_selectedItem);
doc.symbolItems.add(_symbol).position = _selectedItem.position;
_selectedItem.remove();
Best regards

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
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

@rcraighead 

Found another post. I have not tried myself what exactly script is doing but thought it could be useful.

https://community.adobe.com/t5/illustrator-discussions/script-for-randomly-replacing-symbols/m-p/117...

 

Best regards

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

LATEST

@Charu Rajput 

Thanks for the link. I'll review it.

I've since realized I can turn on AI General pref: "Use Preview Bounds" to make boundin box expand to the outside of a stroked path. That was my reason for considering a "Symbol". 

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