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

Open folder image file in photoshop using java script with layer wise.

New Here ,
Sep 24, 2018 Sep 24, 2018

Hi to all,

Dear team,

I am Rakesh from India i have faced an issue with my script, I just want to open a folder image in photoshop with layer wise.

It means suppose i have 2 image file in a folder named "ABC_client.tiff" & "ABC_final.tiff", I want to open both file in single photoshop frame with layered.

I have code a script but it open both file seperately.

So we need a support or help, please update or edit my script.

var dir = Folder('/Users/user/Desktop'); 

var files = dir.openDlg('This is always the same folder?','',true);

if( files !=null ){

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

open(files);

}

}

Thanks

Rakesh

TOPICS
Actions and scripting
4.8K
Translate
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
Guest
Sep 25, 2018 Sep 25, 2018
Translate
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 ,
Sep 25, 2018 Sep 25, 2018

I have search so many JavaScript function in Photoshop Scripting but can't get exact result which i want..

open all folder image in layer wise in photoshop...

If you have you can change or edit my script please do need full.

Thnaks

Translate
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 ,
Sep 25, 2018 Sep 25, 2018

You need to open the first file  then place in then other files or Create a new document open the image files one at a time size them and past them into the document you created where you want the  images and close the image document without saving.

http://www.mouseprints.net/old/dpr/PasteImageRoll.jsx

JJMack
Translate
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 ,
Sep 25, 2018 Sep 25, 2018

Heartly thankful for your reply,

But, sir my query is that i just want to open a folder (suppose 2 .tiff file in a folder Name as  "ABC_Client.tiff" & "ABC_Final.tiff") image in photoshop. I just want to open all image in single photoshop file.Screen Shot 2018-09-25 at 4.26.13 pm.png

for more detail see the attachement.

Thanks

Translate
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
Advocate ,
Sep 25, 2018 Sep 25, 2018

See if this is good for you

app.bringToFront();

// determine Photoshop version number

function getCSVersion() {

return parseInt(app.version);

}

function getFolder() {

// display the Path Entry dialog with Browse option for Photoshop CS

if (getCSVersion() === 10) {

if (dlg.result == 3) { // Browse

return Folder.selectDialog('Select Folder:', Folder('~'));

} else if (dlg.result == 1) { // OK

return Folder(dlg.pathText.text);

} else { // Cancel (dlg.result == 0)

return null;

}

}

// display only the browse dialog for Photoshop CS2+

else {

return Folder.selectDialog('Select Folder Import:', Folder('~'));

}

}

function importFolderAsLayers(selectedFolder) {

// if a folder was selected continue with action, otherwise quit

if (selectedFolder) {

// create document list from files in selected folder

var docList = selectedFolder.getFiles();

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

// open each document in file list

if (docList instanceof File) {

// get the file name

var fName = docList.name.toLowerCase();

// check for supported file formats

if ((fName.indexOf(".tif") == -1)) {

} else {

// if supported documents exist, create a new document

if (!newCanvas) {

// remember unit settings and change to pixels

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var newDoc = app.documents.add(2400, 2400, 200, "Doc temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);

// restore original unit setting

preferences.rulerUnits = originalRulerUnits;

var newCanvas = 1;

}

// combine documents into new document using their original names

open(docList); // open documents from list

var docRef = app.activeDocument;

var docName = docRef.name; // get document name

if (docRef.layers.length > 1) { // merge multilayer documents

docRef.artLayers.add();

docRef.mergeVisibleLayers();

}

docRef.changeMode(ChangeMode.RGB);

// duplicate the layer into the new document

docRef.activeLayer.duplicate(documents[newDoc.name],ElementPlacement.PLACEATBEGINNING);

docRef.close(SaveOptions.DONOTSAVECHANGES);

// name duplicate layer using the original document name

newDoc.activeLayer.name = docName.substring(0, docName.indexOf("."));

}

}

}

// delete empty "Layer 1", then reveal and trim canvas to fit all layers

if (newCanvas) {

app.activeDocument.artLayers["Livello 1"].remove();

app.activeDocument.revealAll();

app.activeDocument.trim(TrimType.TRANSPARENT, false, false, false, false);

} else {

// display error message if no supported documents were found in the designated folder

alert("Sorry, but the designated folder does not contain any files Tif.\n\nPlease choose another folder.");

importFolderAsLayers(getFolder());

}

} else {

alert("The action has been cancelled.");

}

}

importFolderAsLayers(getFolder());

Translate
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 ,
Sep 25, 2018 Sep 25, 2018

You can have a select folder dialog and the get all name in that folder. You would need to filter the=at file list process only files  and only process files that are images,  You would still need to place or paste  in the images into the document you are creating,  If you open the image files you must also close their document after you paste the image into the document you are creating.  I just post a script that paste images into a document it creates. As an example of how you create a document with multiple images. The script I posted also resize the images position the image and mask the resized image to a tile size,

If you process just a few files you can use Place without rasterizing the placed layer.  If you process hundreds if image Place has a very high overhead and would create massive size documents.

I use windows I believe a read somewhere the Dialog file filtering is only used on Windows it may not be useful on a Mac

If you just want to stack images you can use Adobe Load files into a stack.  The script you can select folders and can select files and can modify the file list you build that the script will stack.

JJMack
Translate
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 ,
Sep 25, 2018 Sep 25, 2018

File > Scripts > Load Files into Stack

Translate
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 ,
Sep 25, 2018 Sep 25, 2018

Thanks for reply,

I know about this step but there have manual intervention like select file or folder then check open align option then press open... and I want to create javascript to for plugin design in configurator so we just click plugin button and folder file is automatic open in photoshop with layered.

This is requirement that's why I need a help.

Translate
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 ,
Sep 25, 2018 Sep 25, 2018

If you know what you want to do what is stopping you from coding the script? You can read the code in load files into stack and see how it process a folder to get all the filed in it,  read the code to stack a list of  files

JJMack
Translate
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 ,
Sep 25, 2018 Sep 25, 2018

You can of course modify the code of the standard script that ships with Photoshop if it is not 100% of what you need.

This sort of question comes up from time to time, a search of the scripting forum returned this:

https://forums.adobe.com/search.jspa?q=load+pairs+of+images+as+layers&place=%2Fplaces%2F1383833&dept...

And this:

https://forums.adobe.com/search.jspa?q=load+folder+of+images+as+layers&place=%2Fplaces%2F1383833&dep...

Translate
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
People's Champ ,
Sep 25, 2018 Sep 25, 2018

May be?

var dir = Folder('/Users/user/Desktop');

var files = dir.openDlg('This is always the same folder?','',true);

if (files != null)

    {

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

        {

        if (!f)

            {

            open(files);

            activeDocument.flatten();

            }

        else

            {

            var d = new ActionDescriptor();

            d.putPath(stringIDToTypeID("null"), files);

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

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

            activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);

            }

        activeDocument.activeLayer.name = File.decode(files.name);

        }

    }

Translate
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 ,
Sep 25, 2018 Sep 25, 2018

Hi geppettol66959005,

Thanks for support, Your script is working fine but when i run this, it will open a folder image file in described format, which is mention in script, but i want open image file without mention the size in script..

When i open spread file it is open in half view.

but when i open single page file it is open full but extra transparent margin is there.

If is it possible in script to open document in his own size perfeactly view in Photoshop. (Either it is Page or Spread)

Please do needfull support.

Screen Shot 2018-09-26 at 11.29.57 am.png

Document will automatically open in his own size without mentioning in script.

Thanks

Rakesh

Translate
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
Advocate ,
Sep 26, 2018 Sep 26, 2018

Change line 78

from so

var newDoc = app.documents.add (2400, 2400, 200, "Doc temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);

to

var newDoc = app.documents.add (10000, 1000, 300, "Doc temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);

change line 100

from so

app.activeDocument.trim (TrimType.TRANSPARENT, false, false, false, false);

to

app.activeDocument.trim (TrimType.TRANSPARENT, true, true, true, true);

See if it's okay for your purpose

Translate
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 ,
Sep 27, 2018 Sep 27, 2018

Hi ,

I have change the properties of code which you suggest but result is more poor.

see the result when we update the script (var newDoc = app.documents.add (10000, 1000, 300, "Doc temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);)

Screen Shot 2018-09-28 at 10.55.53 am.png

but we want the result is

Screen Shot 2018-09-28 at 10.57.58 am.png

This is exact result but we donot want to describe the size of image in script, I need help to edit in script that take automatic open the image file  in full size of document either size is big or small it automatically open perfect view accoding to document size. (Auto responsive).

Thanks

Translate
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
Advocate ,
Sep 28, 2018 Sep 28, 2018

The size 10000x10000 is only temporary

at the end it adapts to the format of the photo

check image size

the temporary file is used to maintain the original size

if I do not create the temporary file the script could load one first

smaller image and the larger one adapts to the smaller one

I hope you understand what I wrote.

Translate
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 ,
Sep 26, 2018 Sep 26, 2018

Thanks for reply,

Dear i want to chose folder option not file, we need to open all files in folder at single click.

So can you modify with choose folder option instead of files.

Thanks

Translate
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 ,
Sep 26, 2018 Sep 26, 2018

The code you posted opens the same folder always.  You need to replace that code with a select Folder Dialog the user would navigate to the folder they want to process and select it then the rest of the code will process the selected folder If the folder has none image files as well as image files the script will fail if it has more than 8000 image Photoshop layer level will be exceeded.  You may want to add some code to filter file type and limit the number if images the script will process.  It is you process and workflow design it well.

The following needs to be replaced

var dir = Folder('/Users/user/Desktop');

var files = dir.openDlg('This is always the same folder?','',true);  

With something like this but you should add a filter to filter the File Types that are processed

/////////////////////////////////////////////////////

// Pops open a dialog for the user to

var defaultFolder = "~";   // Users Space

var dir = Folder.selectDialog("Choose a folder of images to process.", defaultFolder);

if  (dir != null)  var files = dir.getFiles();

Also remember r-bin code open the first flattens it  and places the other images in as layers and rasterize the smart object layers.  If your image files have different sizes any image larger then the first one image may be resized sizes to fit within the first document canvas size or may be larger that the canvas size.  Depends on your Photoshop preference for place handling.

Most likely you should add code to verify that the selected folder contains image files you want to process with your script.

JJMack
Translate
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 ,
Sep 28, 2018 Sep 28, 2018

Dear Sir,

Thanks for reply,

I have try it but not get result, May be i have doing something wrong in scriptting, so i am resquesting to you please write the complete script to open the folder image in layerwise automatically.

Upon script working file but there we have select file of folder and i want to select only folder...

Thanks.

Translate
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 ,
Sep 28, 2018 Sep 28, 2018
LATEST

You do not seem to know anything about scripting and may not now how Photoshop works well.  r-bin code uses file place and places in image.  If images are different resolution Photoshop will scale the image for the first image file opened resolution and if the placed smart object is larger than the first files canvas size Photoshop will scale the layer to fit with in the first  file canvas size. If you Preferences as set to scale placed images. If all you image are the same resolution and size you should have  no problem.  Yes you need to navigate to a folder containing your images and select the folder for the script. The script should open the first image and the place the rest of the images in as layers. I commented out the lines of Code I told you to change. If your images are nit the same size and resolution some scaling is likely to happen.

Here I changed the line of code you seem unable too.

//var dir = Folder('/Users/user/Desktop');  

//var files = dir.openDlg('This is always the same folder?','',true); 

////////////////////////////////////////////////////

// Pops open a dialog for the user

var defaultFolder = "~";   // Users Space

var dir = Folder.selectDialog("Choose a folder of images to process.", defaultFolder);

if (dir != null)  var files = dir.getFiles(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|jpg|tif|psd|eps|png|bmp)$/i);

 

if (files != null) 

    { 

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

        { 

        if (!f)  

            {  

            open(files);  

            activeDocument.flatten();  

            }  

        else 

            {  

            var d = new ActionDescriptor(); 

            d.putPath(stringIDToTypeID("null"), files); 

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

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

 

            activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER); 

            } 

 

        activeDocument.activeLayer.name = File.decode(files.name);  

        } 

    } 

JJMack
Translate
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 ,
Sep 25, 2018 Sep 25, 2018

r-bin code open the first flattens it  and places the other image in as layers and rasterize the smart object layers,  If you files have different sized any image larger then the first one may be resized sizes to fit within the first document canvas size or may be larger that the canvas size.  Depends on your Photoshop preference for place handling.

JJMack
Translate
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