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

Script to create new .psd with embedded raw file as smart object

New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

I have a collection of camera raw files.  I would like to create a script that would embed each raw file as a smart object in a new .psd file with the same name as the original raw file.  I'd like to do this from Bridge.  I've done other photoshop scripting but don't see how to do this. 

TOPICS
Actions and scripting

Views

1.2K

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 Expert ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Bridge menu  Tools>Photshop>Image Processor...  Youe ACR Preferences woul neet to be onem as Object.  If Image Processor doe not crerate Smart Object Layers.  try Tools>Photoshop>Batch... make sure your ACR preferences is set to open object. ACR Process RAW files Photoshop does not.

image.png

image.png

JJMack

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Not sure this is what I am after .. I already use the batch processor on collections of files to open them, do some work, and then write the result to a new file of a different type.  I'd like to do the same with the raw files, open each one in turn, embed it in a new document and then write the new document as .psd.   [Understand that PS does not process raw files, but when raw file is embedded as Smart Object ACR can be opened on the Smart Object 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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

The Image Processor will open your RAW files convert the Camera sensor mosaic RAW data image into a RGB Image using the ACR setting you set for the RAW File or use your default ACR setting.  It will create a Photoshop document containing a background layer or  a Smart object layer its object will your RAW File when ACR Preferences is set to OPEN as SMART Object.  The ACR conversion setting used will also be recorded into the smart object layer.  The Image Processor cans save Jpeg, PSD and Tiff.  This seem to be exactly what you wrote that you want. If the PSD file exist in the save location. The Image Process will add a suffix to the Image Document file name.  The image processor design will not destroy existing files by overwriting them.  Your ACR worflow preferences must be set to open smart Objects for what you want done. Other workflow preferences like color space  and bit depth can also be set.

Capture.jpg

JJMack

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

I will look again at the Image Processor.  I am probably not understanding it completely.  In the meantime the Javascript does what I want.

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Try this Javascript, asks for a folder containing .CR2 files, places the in RAW file a new 8-bit .PSD with AdobeRGB assigned and saves back to the same directory:

 

 

 

 

#target photoshop


var f = Folder.selectDialog("Select the folder containing .CR2 Raw files"); 
if(f != null){ 
    fa = f.getFiles(/\.(CR2)$/i);
}


for (var i = 0; i < fa.length; i++){
    
    //a new 8-bit document with AdobeRGB as the profile assignment
    var d = app.documents.add();
    d.mode = DocumentMode.RGB;
    d.bitsPerChannel = BitsPerChannelType.EIGHT
    d.colorProfileName = "Adobe RGB (1998)";
    
    //place the CR2
    placePS(fa[i], true);
    
    //get the width and height of the CR2 layer and size the canvas to match
    var al = d.activeLayer.bounds;
    var w = boundsAsNumbers(al)[2]-boundsAsNumbers(al)[0]
    var h = boundsAsNumbers(al)[3]-boundsAsNumbers(al)[1]
    d.resizeCanvas (w, h, AnchorPosition.MIDDLECENTER);
    
    //get the layer name for the save
    var n = d.layers[0].name;
    
    //remove the backgound layer
    d.layers[1].remove();
    
    //save in the same folder as a .PSD file
    var so = new PhotoshopSaveOptions({embedColorProfile:true, layers:true});
    var sPath = f + "/" + n + ".psd"
    d.saveAs(new File(sPath), so);
    d.close();

};   



/**
* Place action
* @Param file path to place 
* @Return void 
*/
function placePS(p){
    function cTID(s) { return app.charIDToTypeID(s); };
    var placeAction = new ActionDescriptor();
    placeAction.putPath( cTID('null'), new File(p));
    placeAction.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
    executeAction( cTID('Plc '), placeAction, DialogModes.NO );
}


/**
* A layer’s bounds returns an array of strings with ruler unit. Converts to numbers 
* @Return an array of numbers 
* 
*/
function boundsAsNumbers(b){
    return [Number(b[0].toString().split(' ')[0]), Number(b[1].toString().split(' ')[0]), Number(b[2].toString().split(' ')[0]), Number(b[3].toString().split(' ')[0])]
}

 

 

 

 

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

The op want to select the RAW file in Bridge. They not asking about converting RAW file in a folder.

JJMack

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

For smaller batches of images, I would just select the files in Bridge, then CMD/CTRL + R to open into ACR. Then select all files in ACR and open as objects. A script would then step through the open docs and save/close to PSD. The advantage is that this leverages built-in features and only needs the save loop to be scripted. The disadvantage is that open all files at once will take more memory so would not be good for large batches.

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Either Image Processor scripts can do what that user want to do once they select the RAW Files in the Bridge and use Bridge menu Tools>Photoshop>Image Processor as long as the Users ACR  worflow preferences is set to open as smart objects.  They can also set workflow preferences Color space and color bit depth.   If the user has set ACR setting for RAW files in sidecar files or ACR database they will be used, They could have Image processor open the First RAW file into ACR UI so the user can set conversion setting. Then the script will use those settings for converting all the RAW files selected. Or The user can have ACR use the Users  Default ACR settings for RAW file without current ACR conversion settings.  There is no need to save each open PSD manually or write a script to save the open document in Photoshop as PSD files in some location and colse all the open documents. With the Image Processor scripts they will only be working  one Document at at time.  If the were document open in Photoshop they will still be open in photoshop and untouched by the processing done. Not save and closed some scripted loop.

JJMack

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

There is no need to save each open PSD manually or write a script to save the open document in Photoshop as PSD files in some location and colse all the open documents.


By @JJMack

 

I was simply noting another valid, even if less efficient approach to the issue.

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Sorry, I thought the active layer bounds was returning the original RAW pixel dimensions, but it’s not. I think this works:

 

#target photoshop

var f = Folder.selectDialog("Select the folder containing .CR2 Raw files"); 
if(f != null){ 
    fa = f.getFiles(/\.(CR2)$/i);
}


for (var i = 0; i < fa.length; i++){
    
    app.preferences.rulerUnits = Units.PIXELS
    var of = open (fa[i]);
    var w = of.width;
    var h = of.height;
    of.close(SaveOptions.DONOTSAVECHANGES);
    
    //a new 8-bit document with AdobeRGB as the profile assignment
    var d = app.documents.add(w, h, 300.0);
    d.mode = DocumentMode.RGB;
    d.bitsPerChannel = BitsPerChannelType.EIGHT
    d.colorProfileName = "Adobe RGB (1998)";
    
    //place the CR2
    placePS(fa[i], true);
    
    //get the layer name for the save
    var n = d.layers[0].name;
    
    //remove the backgound layer
    d.layers[1].remove();
    
    //save in the same folder as a .PSD file
    var so = new PhotoshopSaveOptions({embedColorProfile:true, layers:true});
    var sPath = f + "/" + n + ".psd"
    d.saveAs(new File(sPath), so);
    d.close();

};   



/**
* Place action
* @Param file path to place 
* @Return void 
* 
*/
function placePS(p){
    function cTID(s) { return app.charIDToTypeID(s); };
    var placeAction = new ActionDescriptor();
    placeAction.putPath( cTID('null'), new File(p));
    placeAction.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
    executeAction( cTID('Plc '), placeAction, DialogModes.NO );
}


 

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Rob,  thanks much, this looks like it will do what I want.  I have done a lot of Javascript programming, but never programmed using the Photoshop API this way.  This will be my entry into that world.   I'll write if I have more questions.  

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Hi Rob .. A very dumb question - Where does this Javascript go and how do I execute it?  

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Paste the code into a new ExtendScript Toolkit file and save it into your scripts folder. If ESTK doesn’t run on your OS, you can use a plain text editor and save with a .jsx extension:

 

Applications⁩ ▸ ⁨Adobe Photoshop 2020⁩ ▸ ⁨Presets⁩ ▸ ⁨Scripts⁩

 

Restart PS and run it from File>Scripts

 

Here’s a compiled version which you can just copy into your scripts folder:

 

 

https://shared-assets.adobe.com/link/bfd6e5b6-1fa5-4e11-4638-ac64e7fad2a2

 

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

ExtendScript Toolkit is being phased out even its open button is grayed out in the Creative Cloud desktop application.

The Creative Desktop Can Still uninstall it though.

image.png

JJMack

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

I hope you are not suggesting that the ability to create Javascript scripts that can be invoked from PS actions is being phased out.

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 ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

ESTK is not a 64-bit app so it won’t run on OSX Catalina or later. The altenative will be to use Visual Studio Code with the ESTK plugin.

 

https://code.visualstudio.com/download

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Thanks.  I realized it was just another script and so it went into a .jsx file and in the scripts folder.  I have quite a number of other .jsx files there that are invoked from PS actions [.atn files].

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Rob .. Never mind .. answered my own dumb question, thanks again.. 

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 ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

That script has a performance problem  it is poor IMO.  The Script open file will open the RAW as a smart Object layer if the user set their ACR Preferences Workflow preferences to open as Object.  The script then closes the document no save  followed that it add new document that Photoshop names something that has right canvas size with a print resolution of 300ppi set color space AdobeRGB. It then Places in the raw file and removes the background layer. We are back to the Original  File open nearly. However the Original open had a document name like the RAW file name any had the users ACR workflow print resolution and Colorspace profile.  Finally the script save a PSD File in the sane Folder as the RAW file with the RAW image name. that would overwrite any existing PSD with that name which would delete any edits the user made to that  PSD.

JJMack

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

For my purposes it does not matter that an existing .psd file might be overwritten.  I plan on running this only at the time I unload raw files from a camera.  I made slight edits to the script for bit depth and color profile.  I might change it so it requests the camera raw suffix, since cameras are all different.  Performance is not really an issue since I'll generally only be running it once on a collection of raw files.  But if you have specific performance changes to suggest please post an edited version of the file; I'd like to see them.

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 ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

The Script open file will open the RAW as a smart Object layer if the user set their ACR Preferences Workflow preferences to open as Object.

 

Hi JJMack, That’s not working for me (PS21.2.2)—the Javascript open() opens the file as a flattened Background layer even when my Camera RAW prefs are set Open as Smart Object. I’m getting the same when I run Image Processor.jsx:

 

Screen Shot 17.png 

 

The open and close is simply to get the pixel dimensions—I can’t find a way to get the RAW pixel dimensions without an open, but would welcome any suggestions. I can do it with AppleScript via image events, but that’s not an option with JS.

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
New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

Rob,  Thanks again for this.  Exactly what I was looking for.  You must do a lot of Javascript programming using the PS API!

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 ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

The regular API’s open() doesn’t seem to have an option to open as a smart object. The last script I posted was a quick translation of an AppleScript I use.

 

With JS there is the option to use ActionDescriptors to get at the smart object boolean—I just didn’t take the time to look at that. This seems to work with a simple open and save and is somewhat faster. The other options like color profile and bit depth are coming from your current Camera RAW prefs but they could be overridden in the open function:

 

 

 

#target photoshop

var f = Folder.selectDialog("Select the folder containing .CR2 Raw files"); 
if(f != null){ 
    fa = f.getFiles(/\.(CR2)$/i);
}


for (var i = 0; i < fa.length; i++){
    openAsSmart(fa[i])
    var d = app.activeDocument
    var n = d.name;
    //save in the same folder as a .PSD file
    var so = new PhotoshopSaveOptions({embedColorProfile:true, layers:true});
    var sPath = f + "/" + n + ".psd"
    d.saveAs(new File(sPath), so);
    d.close();

};   



/**
* Use ActionDescriptors to open RAW as a smart object
*  the file path 
*  void 
* 
*/
function openAsSmart(p){
    var d1 = new ActionDescriptor();
    d1.putPath( stringIDToTypeID( "null" ), new File( p ) );
    var d2 = new ActionDescriptor();
    d1.putObject( stringIDToTypeID( "as" ), stringIDToTypeID( "Adobe Camera Raw" ), d2 );
    d1.putBoolean( stringIDToTypeID( "smartObject" ), true );
    executeAction( stringIDToTypeID( "open" ), d1, DialogModes.NO );
}


 

 

 

 

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 ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

That will perform much better. 

 

With the Image Processor script the user can select which RAW file to process in the Bridge and where they want the PSD saved in the  Image Processor script dialog. The RAW files collection can come from many  folders. Additionally the user could include using an action they record to add additional editing steps to the PSD documents being created.

JJMack

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