Copy link to clipboard
Copied
My solution requires repeated runs of the script, but it works. First save parent layers via object attribute, and restore on request.
/*
RememberLayers.jsx for Adobe Illustrator
Description:
Saving and restoring selected items to their original layers.
The order within the layers is not restored
Author: Sergey Osokin, email: hi@sergosokin.ru
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
function main(
...
Copy link to clipboard
Copied
As far as I know, Illustrator does not yet have this function. (Although InDesign does)
Can you do what you need to do with your multiple selected objects without grouping them?
Copy link to clipboard
Copied
I can, workarounds as I've done thus far. Such feature would speed up the process, though.
Copy link to clipboard
Copied
Same, as per me as well it does not exist, unless if someone has workaround for that.
You can post your feature request at below link.
https://illustrator.uservoice.com/forums/333657-illustrator-desktop-feature-requests
Copy link to clipboard
Copied
Thank you, I'll submit.
Copy link to clipboard
Copied
Hi danielem41796145, as our colleagues said there is no native feature. I don't know what your purpose is with this function, but yes, as you mentioned, it is possible to script it. Would you like me to try?
Copy link to clipboard
Copied
Hi Inacio, fantastic - if you can figure out a script it would be great! Thank you
Copy link to clipboard
Copied
Okay Daniel, tomorrow we will have one. Until then !
Copy link to clipboard
Copied
cool, thank you!
Copy link to clipboard
Copied
I loved the solution provided by our colleague Sergey Osokin. However I believe that sometimes all we need are quick actions, I don't know if that's the case here. As I said before, I couldn't verify what Danielem's demand really is, so I thought we'd walk together in search of a solution. So I suggest starting with a very simple script that just ungroups the objects and sends them each one to a layer, without worrying about keeping the original path of these objects. This script, for example, to be accessed quickly could be assigned a keyboard shortcut.
There is an interesting discussion about this here in the community:
https://community.adobe.com/t5/illustrator-discussions/tutorial-add-your-own-keyboard-shortcuts-to-y...
Now, if it's necessary for Daniel's demand to maintain the objects' original path, Sergey's idea would actually be a better option.
So Danielem, could you exemplify us with a real work? So we could work the script better.
Follow that simple script I mentioned just above.
/*
Name-> UngroupAndMoveToLayer
By-> Inacio Felipe
Where-> https://community.adobe.com/t5/illustrator-discussions/ungroup-objects-back-to-their-own-layers-illustrator/m-p/12658180#M306036
what are you doing->This script detects and ungroups objects into groups on a pre-selection.
Names and moves each item in this undone group to a layer created and named for it.
The name of objects and layers is created from the name of the group that was undone, and the name of each object.
If the group, and or, the object does not have names, it will receive a generic name:
"group 'i' _ iItem _ 'i'", where i is a numeric index
note:
This script works with the layers in the root, elements in the sub layers will be moved to the root
and not to the source layer.
Sugestions:
look for AutoHotkey or
https://community.adobe.com/t5/illustrator-discussions/tutorial-add-your-own-keyboard-shortcuts-to-your-jsx-scripts/m-p/3079389
*/
#target.Illustrator
#targetengine.ungroupAndMoveToLayer()
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
ungroupAndMoveToLayer()
function ungroupAndMoveToLayer(){
doc=app.activeDocument
layers=doc.layers
sel=doc.selection
groups=doc.groupItems
try{
if (app.documents.length<1){
alert('Open document for work')
return
}
else{
// Verify if there is one selection
if (sel.length<1){
alert('No items selected. Select something to continue')
return;
}else{
// Verify if there is groups in the selection
j=0
idGroup=0
for (ii=0; ii<sel.length; ii++){
if (sel[ii].typename=="GroupItem"){
j++
idGroup+=1
//alert('Work with the group,' + idGroup + '\nwith a name: ' + groups[i].name + '\nwhere exists ' + sel[i].pageItems.length + ' items')
ungroupAndMakeLayer(sel[ii],idGroup)
}
}
if(j==0){
alert('Nothing for do. No groups in the selection')
return;
}
}
}
}
catch(erro){
alert ("The script don't run because:\n" + erro)
}
}
function ungroupAndMakeLayer(group,idGroup){
idItem=0
for(i=group.pageItems.length-1; i>=0; i--){
idItem=i+1
// Rules for naming layers
strGroupName=group.name
if(strGroupName=='null' || strGroupName==''){
strGroupName='group ' + idGroup
}else{
strGroupName=group.name
}
strItemName=group.pageItems[i].name
if(strItemName=='null' || strItemName==''){
strItemName='item_'+ idItem
}else{
strItemName=group.pageItems[i].name
}
//
strLayerName=strGroupName + '_' + strItemName
level=doc.layers
//make the layer
newLayer=makeLayer(level,strLayerName)
group.pageItems[i].move(newLayer,ElementPlacement.PLACEATBEGINNING)
//moves the new layer to layer of group
layerOfGroup=group.parent
moveToLayer(newLayer, layerOfGroup.name)
redraw()
}
}
function makeLayer(level,strName){
/* Essa funcao cria e retorna uma nova camada se ela nao existir no nivel indicado
parametros:
-> nivel:
nivel onde sera criada a camada.
Ex.:
'app.activeDocument.layers' para o primeiro nivel
'app.activeDocument.layers[index].layer' para outros niveis
-> strNome:
string com o nome que sera atribuido a nova layer
*/
var newLayer
try {
newLayer = level.getByName(strName);
} catch (e) {
// no layer by that name, so make it
newLayer = level.add()
newLayer.name = strName;
}
return newLayer;
}
function moveToLayer(item, strName) {
/*
Essa função move o item, para a camada com o nome
-> item:
qualquer item do illustrator
-> strName:
string com o nome da camada para onde será movido o item
*/
var level
try {
level = activeDocument.layers.getByName(strName)
item.move(level, ElementPlacement.PLACEATBEGINNING)
} catch (e) {}
}
Copy link to clipboard
Copied
Hi!
Both solutions work, in different ways and will serve different purposes. I'll use them both!
Thank you!
Copy link to clipboard
Copied
My solution requires repeated runs of the script, but it works. First save parent layers via object attribute, and restore on request.
/*
RememberLayers.jsx for Adobe Illustrator
Description:
Saving and restoring selected items to their original layers.
The order within the layers is not restored
Author: Sergey Osokin, email: hi@sergosokin.ru
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
function main() {
if (!documents.length) return;
if (selection.length == 0 || selection.typename == 'TextRange') return;
var doc = activeDocument,
docSel = selection,
keyPref = 'origLayer=';
// DIALOG
var dialog = new Window('dialog', 'Remember Layers');
dialog.preferredSize.width = 146;
dialog.orientation = 'column';
dialog.alignChildren = ['fill', 'center'];
var saveBtn = dialog.add('button', undefined, 'Save');
var restoreBtn = dialog.add('button', undefined, 'Restore');
var cancel = dialog.add('button', undefined, 'Cancel', {name: 'cancel'});
var copyright = dialog.add('statictext', undefined, '\u00A9 Sergey Osokin');
copyright.justify = 'center';
copyright.enabled = false;
saveBtn.onClick = save;
restoreBtn.onClick = restore;
cancel.onClick = dialog.close;
function save() {
for (var i = 0, len = selection.length; i < len; i++) {
var currItem = selection[i];
removeNote(currItem, keyPref);
currItem.note += keyPref + currItem.layer.name + ';';
}
dialog.close();
}
function restore() {
var regexp = new RegExp(keyPref + '(.+)', 'g')
for (var i = selection.length - 1; i >= 0; i--) {
var currItem = selection[i],
layerName = '';
if (currItem.note.match(keyPref) !== null) {
layerName = currItem.note.split(';')[0].replace(regexp, '$1');
moveToLayer(currItem, layerName);
}
removeNote(currItem, keyPref);
}
dialog.close();
}
dialog.center();
dialog.show();
}
// Remove keyword from Note in Attributes panel
function removeNote(item, key) {
var regexp = new RegExp(key + '(.+);', 'g');
item.note = item.note.replace(regexp, '');
}
// Move selected item to original Layer by name
function moveToLayer(item, name) {
var origLayer;
try {
origLayer = activeDocument.layers.getByName(name);
item.move(origLayer, ElementPlacement.PLACEATBEGINNING);
} catch (e) {}
}
try {
main()
} catch (e) {}
Copy link to clipboard
Copied
Thank you so much, I'll give it a try!
Copy link to clipboard
Copied
It works. thank you.