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

Name of linked File in a Frame

Participant ,
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

616

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

Community Expert , 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
...

Votes

Translate

Translate
Adobe
Community Expert ,
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

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
Participant ,
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.?

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 ,
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

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
Participant ,
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.

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 ,
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

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
Participant ,
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! 

 

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 ,
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

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