Name of linked File in a Frame

Explorer ,
May 02, 2021 May 02, 2021

Copy link to clipboard

Copied

Hello,
Maybe you can help me?
I am trying to read the linked document from a frame and put the name in a text layer.
Somehow I only get the layer name and not the name of the image that is in the frame.
Maybe it would also be great if someone knows how to delete the ending (.jpg) directly at the end.

many thanks in advance.

TOPICS
Actions and scripting

Views

346

Likes

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

correct answers 1 Correct Answer

Adobe Community Professional , May 03, 2021 May 03, 2021
Try the following code function getDescriptor(className) { var r = new ActionReference () r.putEnumerated (stringIDToTypeID (className), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum")); var d = executeActionGet(r) return d } var currLayer = app.documents[0].activeLayer if(currLayer.kind == LayerKind.SMARTOBJECT) { var d = getDescriptor("layer") var so = d.getObjectValue(stringIDToTypeID("smartObject")) var a if(so.hasKey(stringIDToTypeID("fileReference"))) { a = so.g...

Likes

Translate

Translate
Adobe Community Professional ,
May 02, 2021 May 02, 2021

Copy link to clipboard

Copied

Try the following code, it will alert the file name of the linked image present on the currently active layer.

 

function getDescriptor(className)
{
	var r = new ActionReference ()
	r.putEnumerated (stringIDToTypeID (className), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum"));
	var d = executeActionGet(r)
	return d
}
var currLayer = app.documents[0].activeLayer
if(currLayer.kind == LayerKind.SMARTOBJECT)
{
	var d = getDescriptor("layer")
	var so = d.getObjectValue(stringIDToTypeID("smartObject"))
	if(so.getBoolean(stringIDToTypeID("linked")))
	{
		var f = so.getPath(stringIDToTypeID("link"))
		var a = f.name.match(/(.*)\./)
		alert(a[1])
	}
}

Edit:- Removed unused code

 

-Manan

Likes

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
Explorer ,
May 02, 2021 May 02, 2021

Copy link to clipboard

Copied

Hi Manan,

 

Thank you for your fast answer, but i try´d it but it wont work.

No alert is shown.?

Likes

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 Professional ,
May 02, 2021 May 02, 2021

Copy link to clipboard

Copied

Can you send me a sample file for which it does not work, so that I can debug it?

-Manan

Likes

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
Explorer ,
May 02, 2021 May 02, 2021

Copy link to clipboard

Copied

here ist the file:

https://we.tl/t-YVY1VjDuo5

 

but you must link the image into the frame.

my goal is to create captions for the frames with the name of the image in a text layer.

Likes

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 Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Try the following code

 

function getDescriptor(className)
{
	var r = new ActionReference ()
	r.putEnumerated (stringIDToTypeID (className), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum"));
	var d = executeActionGet(r)
	return d
}

var currLayer = app.documents[0].activeLayer
if(currLayer.kind == LayerKind.SMARTOBJECT)
{
	var d = getDescriptor("layer")
	var so = d.getObjectValue(stringIDToTypeID("smartObject"))
	var a
	if(so.hasKey(stringIDToTypeID("fileReference")))
	{
		a = so.getString(stringIDToTypeID("fileReference"))
	}
	if(a)
		alert(a.match(/(.*)\./)[1])
}

 

-Manan

Likes

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
Explorer ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Hi Manan,

 

I Tryed again and without the layerkind line it works 🙂 

 

Thank you! 

 

Likes

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 Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

LATEST

Interesting I did test the code on your document and it works for me just fine

-Manan

Likes

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