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

Access to saved selection with Java Script

Guest
Sep 21, 2010 Sep 21, 2010

Copy link to clipboard

Copied

Hello,

I'm a newbie with Java Script, and I'm looking if there is a solution to access to all items included in a saved selection ?

I've tried differents ways without success

Thanks for your help.

TOPICS
Scripting

Views

1.1K

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
Community Beginner ,
Sep 23, 2010 Sep 23, 2010

Copy link to clipboard

Copied

i'm not sure what you means with "saved selection".

You can have the list of selected object with this function:

var docSelected = app.activeDocument.selection;

it returns an array of objects.

Hope this is what you need

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 ,
Sep 23, 2010 Sep 23, 2010

Copy link to clipboard

Copied

I think the question is about the save selection in the app menubar that you can return to retrieve the same objects over and over… And to that I would think NOT…

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
Guest
Sep 23, 2010 Sep 23, 2010

Copy link to clipboard

Copied

Yes I talk about the fonction in the selection "menubar".

And your answer is not a good news !

In fact I'm using "groupItems" with name selection to achieve my goal. 

Thanks for your help.

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 ,
Sep 23, 2010 Sep 23, 2010

Copy link to clipboard

Copied

I have good news, you could "tag" your saved selection objects in the GUI, then select them when needed via script.

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
Guest
Sep 30, 2010 Sep 30, 2010

Copy link to clipboard

Copied

Thanks for your answer.

Could you tell me more ? I have tried to find something in the help menu > Object Model without success

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 ,
Sep 30, 2010 Sep 30, 2010

Copy link to clipboard

Copied

What you want to be looking up in the object model is 'tags' and how to use someArtItem.tags.add(); Apply some names or values so that you can loop and retrieve later… Tip. don't use spaces in the name property…

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
Guest
Oct 01, 2010 Oct 01, 2010

Copy link to clipboard

Copied

Thanks again.

I will try the 'tag" way, but in fact documents have already saved selection...

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 ,
Oct 01, 2010 Oct 01, 2010

Copy link to clipboard

Copied

sorry, I meant "note" instead of tag. yes, saved selections already exist, do the following

in the GUI

- select your saved selection

- add a note

savedSelection.PNG

in your script

- go tru all items and select the ones matching the note

VBA sample:

    For Each pgitem In Idoc.PageItems
        If pgitem.Note = "circles" Then
            pgitem.Selected = True
        End If
    Next

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 ,
Oct 02, 2010 Oct 02, 2010

Copy link to clipboard

Copied

Carlos, its almost the same thing but I would have gone for what you suggested the first time with 'tags'… You could give selected items a name or a note so that you can retrieve later but in both these cases each item can only have the 1 where as with tags items could have multi tags so a single item could be re-selected as part of numerous selected groupings… Any how an example of tagging a selection…

#target illustrator var docRef = app.activeDocument; var     docSel = docRef.selection; //$.writeln(docSel.length+' Selected Items…'); if (docSel.length > 0) tagSelection(docSel,'Foo'); docRef.selection = null; app.redraw(); var     docTags = docRef.tags; //$.writeln(docTags.length+' Item Tags…'); if (docTags.length > 0) selectTaggged(docTags,'Foo'); //docRef.tags.getByName('Foo').parent.selected = true; function tagSelection(docSel,ts) {      for (var i = 0; i < docSel.length; i++) {           var selTag = docSel.tags.add();           selTag.name = ts;           selTag.value = ts;      } } function selectTaggged(docTags,tv) {      for (var i = 0; i < docTags.length; i++) {           if (docTags.value == tv) {                docRef.tags.parent.selected = true;           }      } }

An open document is presumed…

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
Guest
Oct 04, 2010 Oct 04, 2010

Copy link to clipboard

Copied

LATEST

Hello Mark and Carlos, I appreciate your help.

But with your solution, the user must select by him-self object first, and I want to make batch with this script without interaction.

With your helpfull advice I have write and it's not so bad !

#target illustrator doc = app.activeDocument; for ( i = 0; i < doc.groupItems.length; i++ ) { elemt = doc.groupItems; groupName = new String( elemt.name ) ; if ( groupName.indexOf ("PdG") == 0) { elemt.selected = true; var newItem; var newDoc = app.documents.add(); elemt.selected = false; newItem = elemt.duplicate( newDoc, ElementPlacement.PLACEATEND ); doc2=app.activeDocument;    var myVisibleBounds = doc2.pageItems[0].visibleBounds; doc2.artboards[0].artboardRect = myVisibleBounds; //aiDocument = app.activeDocument; //aiDocument.close( SaveOptions.DONOTSAVECHANGES ); var exportOptions = new ExportOptionsJPEG(); var type = ExportType.JPEG; var fileSpec = new File('/Users/gaguad19/Documents/'); exportOptions.antiAliasing = false; exportOptions.qualitySetting = 70; app.activeDocument.exportFile( fileSpec, type, exportOptions ); } else {      alert("Encore raté");     }}

Now I must try to name the JPEG with the Illustrator file name !

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