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.
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
...
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
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.?
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
Copy link to clipboard
Copied
here ist the file:
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.
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
Copy link to clipboard
Copied
Hi Manan,
I Tryed again and without the layerkind line it works 🙂
Thank you!
Copy link to clipboard
Copied
Interesting I did test the code on your document and it works for me just fine
-Manan