Place linked using script

Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

I am looking for a way to place linked photos directly from Lightroom.

After selecting a layer, I want to run my script which will do the following:

  • Get the layer name (this will be the linked filename + suffix, at this point dgn)
  • Open a “browse” dialog using  Folder.selectDialog to get the root path the file can be found in.
  • Recursively search down and if fileName.dgn is found place it as linked and delete the current layer.
    Or, convert the smart object in the active layer to linked

How can I recursively search down to find the file?

How can I place it as linked?

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

Replace

descriptor.putObject( stringIDToTypeID( "openAs" ), charIDToTypeID( "null" ), descriptor2 );

with

descriptor.putObject(stringIDToTypeID("openAs"), stringIDToTypeID("Adobe Camera Raw"), descriptor2 );

TOPICS
Actions and scripting

Views

1.3K

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

Place linked using script

Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

I am looking for a way to place linked photos directly from Lightroom.

After selecting a layer, I want to run my script which will do the following:

  • Get the layer name (this will be the linked filename + suffix, at this point dgn)
  • Open a “browse” dialog using  Folder.selectDialog to get the root path the file can be found in.
  • Recursively search down and if fileName.dgn is found place it as linked and delete the current layer.
    Or, convert the smart object in the active layer to linked

How can I recursively search down to find the file?

How can I place it as linked?

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

Replace

descriptor.putObject( stringIDToTypeID( "openAs" ), charIDToTypeID( "null" ), descriptor2 );

with

descriptor.putObject(stringIDToTypeID("openAs"), stringIDToTypeID("Adobe Camera Raw"), descriptor2 );

TOPICS
Actions and scripting

Views

1.3K

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
Nov 04, 2018 0
Most Valuable Participant ,
Nov 04, 2018

Copy link to clipboard

Copied

karpiyon  wrote

I am looking for a way to place linked photos directly from Lightroom.

After selecting a layer, I want to run my script which will do the following:

  • Get the layer name (this will be the linked filename + suffix, at this point dgn)
  • Open a “browse” dialog using  Folder.selectDialog to get the root path the file can be found in.
  • Recursively search down and if fileName.dgn is found place it as linked and delete the current layer.
    Or, convert the smart object in the active layer to linked

How can I recursively search down to find the file?

How can I place it as linked?

How would  what you wrote be directly from Lightroom?

If you select a layer you are in Photoshop Lightroom does not support Layers.

If you target a layer in Photoshop then use place.  Place will create a Smart Object Layer above the current targeted layer and this new smart object layer will be Photoshop new current target.   If you want the Placed image file to be linked you would use Place linked not place embedded.  So the current layer would be a smart object layer with a linked image file in the layers object.  If you delete the current layer you delete the smart object layer you just placed in.  Lightroom had no part in this process.  You may have saved the file you place in using Lightroom in the past.   That was not part of your script's process.

Your script Process would put the Photoshop User into a select image file dialog.  (Not a folder select dialog) The user would navigate to the file to want placed in and select that file.  The Script would then use place Linked to place in the smart object layer with the linked image file.   The layer will not be an independent smart object layer it will be linked to you master image file.

JJMack

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
Reply
Loading...
Nov 04, 2018 0
Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

Let me rephrase...

In LR I select the image ans open as smart object in PS

In PS I run my script on the smart object layer.

The reason i do this is because i do not want to navigate to the location of the image and search for it - it is time consuming task.

In my script I specify the root folder and it looks for a file whose name is equal to the PS smart layer name.

Currently i have most of the script including the recursive search for the file.

What need is a was to insert/place a file as linked from withing PS by scripting.

Dan

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
Reply
Loading...
Nov 04, 2018 0
Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

The above is not done directly from LR but will save a lot for time.

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
Reply
Loading...
Nov 04, 2018 0
Most Valuable Participant ,
Nov 04, 2018

Copy link to clipboard

Copied

OK I see you open you lightroom image in Photoshop as a smart object layer instead of a background image.   When your in Photoshop with this smart object bottom layer you want a script to find the file that was open as an embedded object.  Then Place the image in as a linked object  in a smart object layer then delete the original  opened embedded object layer.

I would be concerned that recursive searching folders will take some time and may find a file  with duplicate file name, fine the wrong file as a match. Do you plain of verifying you found  the correct image file?

To do the File Place you will most likely need to use action manager code coded as a function where you pass the full path of the file to be placed in.   You would use action manager code for menu File>Place Linked.

scriptlistener code for place linked

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc14 = new ActionDescriptor();

    var idIdnt = charIDToTypeID( "Idnt" );

    desc14.putInteger( idIdnt, 3 );

    var idnull = charIDToTypeID( "null" );

    desc14.putPath( idnull, new File( "C:\\LO2G5037.CR2" ) );

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc14.putBoolean( idLnkd, true );

    var idOpAs = charIDToTypeID( "OpAs" );

        var desc15 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc14.putObject( idOpAs, idnull, desc15 );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc14.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc16 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPrc = charIDToTypeID( "#Prc" );

        desc16.putUnitDouble( idHrzn, idPrc, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPrc = charIDToTypeID( "#Prc" );

        desc16.putUnitDouble( idVrtc, idPrc, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc14.putObject( idOfst, idOfst, desc16 );

executeAction( idPlc, desc14, DialogModes.NO );

Code cleaned by Clean SL script

// =======================================================

placeEvent(3, new File( "C:\\LO2G5037.CR2" ), true, 0, 0);

function placeEvent(ID, null2, linked, horizontal, vertical) {

var descriptor = new ActionDescriptor();

var descriptor2 = new ActionDescriptor();

var descriptor3 = new ActionDescriptor();

descriptor.putInteger( stringIDToTypeID( "ID" ), ID );

descriptor.putPath( charIDToTypeID( "null" ), null2 );

descriptor.putBoolean( stringIDToTypeID( "linked" ), linked );

descriptor.putObject( stringIDToTypeID( "openAs" ), charIDToTypeID( "null" ), descriptor2 );

descriptor.putEnumerated( stringIDToTypeID( "freeTransformCenterState" ), stringIDToTypeID( "quadCenterState" ), stringIDToTypeID( "QCSAverage" ));

descriptor3.putUnitDouble( stringIDToTypeID( "horizontal" ), stringIDToTypeID( "percentUnit" ), horizontal );

descriptor3.putUnitDouble( stringIDToTypeID( "vertical" ), stringIDToTypeID( "percentUnit" ), vertical );

descriptor.putObject( stringIDToTypeID( "offset" ), stringIDToTypeID( "offset" ), descriptor3 );

executeAction( stringIDToTypeID( "placeEvent" ), descriptor, DialogModes.NO );

}

JJMack

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
Reply
Loading...
Nov 04, 2018 0
Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

Yes, i'm aware of the fact i may find more than one candidate.

As for the search time, i allow the user to specify the root folder for search to reduce search time.

I attached my script below, assuming i find only one file, I am unable to "return" it from my recursion.

In this case i always get it as undefined.

SO i have 2 questions:

1. What do i need to change in order to make sure i get required search result,in this case: "foundFile"

I tried modifying the end recursive return traverseFolder(files, layerN);  but that ruined all the function.

The best would be to return a global variable but i failed to do this as well.

2. how do i use the action manager code for menu File>Place Linked in my script once i have the full path to the required file.

This is my script so far:

var doc = app.activeDocument;

var fName = doc.name.split(".");

var fName = fName[0];

var layerN = doc.activeLayer.name;

var linkFolder = Folder.selectDialog("Selection prompt");

if(linkFolder !== null){

    var linkFolderPath = linkFolder.path;

    var linkName = linkFolder.name;

    var linkFullPath = linkFolderPath+"/"+linkName;

    //alert("Looking for " + layerN + " in\n" + linkFullPath);

    function traverseFolder(path, layerN)  { 

        var folder = new Folder(path); 

        suffix = new Array();

        suffix[0] = "tif";

        suffix[1] = "dng";

        suffix[2] = "psd";

        var files = folder.getFiles(); 

        for (var i = 0; i < files.length; i++) 

        { 

            if (files instanceof File) 

            {  

                var fullPathName = Folder.decode(files);

                var fileName = files.name;

                fileName = decodeURI(fileName);

                for(var s = 0; s < suffix.length ; s++){

                    search_name = layerN + "." + suffix;

                    search_NAME = layerN + "." + suffix.toUpperCase();

                    if ((fileName == search_name) || (fileName == search_NAME)) 

                    { 

                        foundFile = fullPathName + "/" + fileName;

                        alert("Found: " + foundFile); 

                        return foundFile ;

                    }

                }

            } 

            else 

            { 

               traverseFolder(files, layerN); 

               // return traverseFolder(files, layerN); 

            } 

        } 

    } 

    var foundFile = traverseFolder(linkFullPath, layerN);

    alert("Found: " + foundFile);

}

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
Reply
Loading...
Nov 04, 2018 1
Most Valuable Participant ,
Nov 04, 2018

Copy link to clipboard

Copied

I posted the File Place Link Action manager code in my previous post.   I do not know javascript I just hack at it.  Looking at what you posted do not see a not found return indicator.  So if not found I do not now what would be returned by your function.   I do not know javascript.

JJMack

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
Reply
Loading...
Nov 04, 2018 0
Engaged ,
Nov 04, 2018

Copy link to clipboard

Copied

I run your added code and i get. in the extendedScript tool:

General Photoshop error occurred. This function may not be available in this version of Photoshop.

well, of course it is available...

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
Reply
Loading...
Nov 04, 2018 0
Most Valuable Participant ,
Nov 04, 2018

Copy link to clipboard

Copied

Did you change the code to make it a function and pass a valid  image file  or create a "C:\LO2G5037.CR2"?

JJMack

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
Reply
Loading...
Nov 04, 2018 0