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.
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
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…
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.
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.
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
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…
Copy link to clipboard
Copied
Thanks again.
I will try the 'tag" way, but in fact documents have already saved selection...
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
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
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…
Copy link to clipboard
Copied
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 !