Skip to main content
Known Participant
January 11, 2021
Answered

Script that renames <group> layer name to the name of the linked file it was embedded from

  • January 11, 2021
  • 3 replies
  • 785 views

I am looking for a script that will rename the layer name <group> with the linked file name it was embedded from . I will try my best to explain with screenshots.  

 

The Process:

 

I bring in files and place them on an artboard.  Each layer is given the name <linked file>.

 

Once I embed the links the layer name is changed to <group>

I would like to replace the <group> name with the linked file name it was originally connected with. 

I think this is possible with scripting, but I'm not sure. 

 

Any help is greatly appreciated.  

Thanks!

 

 

 

This topic has been closed for replies.
Correct answer Silly-V

Try this snippet out, it may be what you are looking for!

 

#target illustrator
function test () {
	var doc = app.activeDocument;
	var thisPlacedItem;
	var newGroup;
	var thisPlacedFile;
	var thisName;
	for (var i = doc.placedItems.length - 1; i > -1; i--) {
		thisPlacedItem = doc.placedItems[i];
		thisPlacedFile = thisPlacedItem.file;
		thisName = decodeURI(thisPlacedFile.name);
		newGroup = thisPlacedItem.parent.groupItems.add();
		newGroup.move(thisPlacedItem, ElementPlacement.PLACEBEFORE);
		newGroup.name = thisName;
		thisPlacedItem.move(newGroup, ElementPlacement.INSIDE);
		thisPlacedItem.embed();
	}
};
test();

 

3 replies

Participant
February 3, 2021

Hey @Silly-V

 

would this work in photoshop?

millerkuAuthor
Known Participant
January 11, 2021

Worked like a dream!

 

I mean this when I say it...  You are my hero Silly-V!

Silly-V
Silly-VCorrect answer
Legend
January 11, 2021

Try this snippet out, it may be what you are looking for!

 

#target illustrator
function test () {
	var doc = app.activeDocument;
	var thisPlacedItem;
	var newGroup;
	var thisPlacedFile;
	var thisName;
	for (var i = doc.placedItems.length - 1; i > -1; i--) {
		thisPlacedItem = doc.placedItems[i];
		thisPlacedFile = thisPlacedItem.file;
		thisName = decodeURI(thisPlacedFile.name);
		newGroup = thisPlacedItem.parent.groupItems.add();
		newGroup.move(thisPlacedItem, ElementPlacement.PLACEBEFORE);
		newGroup.name = thisName;
		thisPlacedItem.move(newGroup, ElementPlacement.INSIDE);
		thisPlacedItem.embed();
	}
};
test();