Skip to main content
Inspiring
April 20, 2022
Answered

How to get the Smart object linked file location

  • April 20, 2022
  • 3 replies
  • 5859 views

 

Hi everyone,

what a learning curve with this photoshop integration. It is very interesting but also a little bit frustrating.

I got some smart objects and the end goal is to change the linked file locations.

But first I need to know what the current location is.

Has anyone got some very simple code that does it?

Even better if it is VBScript or a bonus point for vb.net but I will take what I can get.

Thanking you very kindly.

Henry

This topic has been closed for replies.
Correct answer henry22453428ow9z

Firstly thanks to everyone for your help. It was a very painful process but without your help it would of been impossible. 

I followed the links over to (https://community.adobe.com/t5/photoshop-ecosystem-ideas/is-there-an-option-that-shows-me-a-list-with-all-smart-objects-paths/idc-p/12689475)

went through the jscript(??) and slowly translated it vb.net. Very interesting language, very easy to follow. I thought it might be helpful to other people so I posted my code. 

 

top of the class
imports photoshop  


following in a button action, class, function  etc...

      Dim ref
        Dim applicationDesc
        Dim theNumber
        Dim layerDesc
        Dim isSmartObject
        Dim theSO
        Dim theLink
        Dim ps_app As New Photoshop.Application
        ref = New ActionReference
        ref.putProperty(ps_app.StringIDToTypeID("property"), ps_app.StringIDToTypeID("numberOfLayers"))
        ref.putEnumerated(ps_app.CharIDToTypeID("Dcmn"), ps_app.CharIDToTypeID("Ordn"), ps_app.CharIDToTypeID("Trgt"))
        applicationDesc = ps_app.ExecuteActionGet(ref)
        theNumber = applicationDesc.getInteger(ps_app.StringIDToTypeID("numberOfLayers"))

        Dim m = 0
        Dim n = 0

        Do While m <= theNumber
            ref = New ActionReference ' might fall over as it is already declared above
            ref.putIndex(ps_app.CharIDToTypeID("Lyr "), m)
            layerDesc = ps_app.ExecuteActionGet(ref)
            isSmartObject = layerDesc.hasKey(ps_app.StringIDToTypeID("smartObject"))

            If isSmartObject = True Then
                theSO = layerDesc.getObjectValue(ps_app.StringIDToTypeID("smartObject"))
                If theSO.getBoolean(ps_app.StringIDToTypeID("linked")) = True Then
                    theLink = theSO.getPath(ps_app.StringIDToTypeID("link")) ' this will give the path
                End If
            End If

            m = m + 1
        Loop

 

3 replies

Kukurykus
Legend
April 20, 2022
sTT = stringIDToTypeID; (ref = new ActionReference())
.putProperty(sTT('property'), sO = sTT('smartObject'))
ref.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
executeActionGet(ref).getObjectValue(sO).getPath(sTT('link')).fsName
Stephen Marsh
Community Expert
Community Expert
April 20, 2022

@henry22453428ow9z wrote:

I got some smart objects and the end goal is to change the linked file locations.

But first I need to know what the current location is.

Has anyone got some very simple code that does it?



 
A simplistic JS approach for a single active SO layer (this would need to be looped over multiple layers):
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
alert(decodeURI(activeDocument.path) + "/" + activeDocument.name);
 
Perhaps the following topic is what you are after:
 
EDIT: While I'm at it, this is also possible with ExifTool:
exiftool -XMP-xmpMM:IngredientsFilePath 'Mac path to/file.psd'

or

exiftool -IngredientsFilePath "Win path to\file.psd"
henry22453428ow9zAuthorCorrect answer
Inspiring
April 22, 2022

Firstly thanks to everyone for your help. It was a very painful process but without your help it would of been impossible. 

I followed the links over to (https://community.adobe.com/t5/photoshop-ecosystem-ideas/is-there-an-option-that-shows-me-a-list-with-all-smart-objects-paths/idc-p/12689475)

went through the jscript(??) and slowly translated it vb.net. Very interesting language, very easy to follow. I thought it might be helpful to other people so I posted my code. 

 

top of the class
imports photoshop  


following in a button action, class, function  etc...

      Dim ref
        Dim applicationDesc
        Dim theNumber
        Dim layerDesc
        Dim isSmartObject
        Dim theSO
        Dim theLink
        Dim ps_app As New Photoshop.Application
        ref = New ActionReference
        ref.putProperty(ps_app.StringIDToTypeID("property"), ps_app.StringIDToTypeID("numberOfLayers"))
        ref.putEnumerated(ps_app.CharIDToTypeID("Dcmn"), ps_app.CharIDToTypeID("Ordn"), ps_app.CharIDToTypeID("Trgt"))
        applicationDesc = ps_app.ExecuteActionGet(ref)
        theNumber = applicationDesc.getInteger(ps_app.StringIDToTypeID("numberOfLayers"))

        Dim m = 0
        Dim n = 0

        Do While m <= theNumber
            ref = New ActionReference ' might fall over as it is already declared above
            ref.putIndex(ps_app.CharIDToTypeID("Lyr "), m)
            layerDesc = ps_app.ExecuteActionGet(ref)
            isSmartObject = layerDesc.hasKey(ps_app.StringIDToTypeID("smartObject"))

            If isSmartObject = True Then
                theSO = layerDesc.getObjectValue(ps_app.StringIDToTypeID("smartObject"))
                If theSO.getBoolean(ps_app.StringIDToTypeID("linked")) = True Then
                    theLink = theSO.getPath(ps_app.StringIDToTypeID("link")) ' this will give the path
                End If
            End If

            m = m + 1
        Loop

 

Kukurykus
Legend
April 22, 2022

Nice job - thanks for sharing vbscript code, unusual for this forum!

 

Moderator - remove extra ')' character from end of link posted by user.

Bojan Živković11378569
Community Expert
Community Expert
April 20, 2022

I am not script guy. There is requested info on Window > Properties panel, just ensure that linked Smart Object is selected in the Layers panel then  open Window > Properties and you should see file location.

Inspiring
April 20, 2022

Actually, I did not know that. I was always baffled on how to see that.  That will come in handy.

But need to be able to script the whole thing. Something like 30 objects per page x 40 something pages and growing. 

Just silly for me to manually.