Skip to main content
Participating Frequently
May 20, 2019
Question

ContactSheet problem

  • May 20, 2019
  • 4 replies
  • 798 views

Hi all,

I've made a ContactSheet script that makes a contact sheet from all the images in a folder and it works fine. And it looks like this:

var myFolder = Folder.selectDialog("Select Folder");

var myFileList = myFolder.getFiles();

//Set ContactSheet II parameters

function createContactSheet(folderName){ 

var id = stringIDToTypeID( "0B71D221-F8CE-11d2-B21B-0008C75B322C" ); 

    var desc1 = new ActionDescriptor(); 

    var idCSIISettings = stringIDToTypeID( "CSIISettings" ); 

    desc1.putString( idCSIISettings, '<ContactSheetIISettings>'+ 

  '<source imageSource="Folder" path="'+ folderName +'" includeSubfolders="false" groupImages="false"/>'+ 

  '<document units="cm" width="41" height="27.7" resolution="300" resUnits="pixels/inch" mode="CMYK Color" bitDepth="8-bit" colorProfile="Working CMYK" flattenLayers="true"/>'+ 

  '<thumbnail place="across first" cols="' + myColumns + '" rows="' + myRows + '" bestFit="true" useAutospacing="true" horz="0.014 in" vert="0.014 in"/>'+ 

  '<caption enabled="true">'+ 

   '<font name="ArialMT" size="9.5"/>'+ 

  '</caption>'+ 

'</ContactSheetIISettings>' ); 

    var idMsge = charIDToTypeID( "Msge" ); 

    desc1.putString( idMsge, "Settings for Contact Sheet II" ); 

executeAction( id, desc1, DialogModes.NO); 

}

//Hides the ContactSheet II dialog window, but in order to work it's necessary to edit Photoshop's ContactSheet.jsx

$.setenv("NoUI", true);

createContactSheet(myFolder); 

Now I'm trying to make a similar script, but instead of picking a folder, I need to select certain files. So I changed the script to this:

var myFileList = File.openDialog("Select a File:","*.jpg;*.eps;*.tif;*.psd",true);

var myFolder = myFileList[0].path;

//Set ContactSheet II parameters

function createContactSheet(filesName){ 

var id = stringIDToTypeID( "0B71D221-F8CE-11d2-B21B-0008C75B322C" ); 

    var desc1 = new ActionDescriptor(); 

    var idCSIISettings = stringIDToTypeID( "CSIISettings" );

    var folderName=filesName[0].parent.fsName;

    desc1.putString( idCSIISettings, '<ContactSheetIISettings>'+ 

  '<source imageSource="Files" path="'+ folderName +'" includeSubfolders="false" groupImages="false"/>'+ 

  '<document units="cm" width="41" height="27.7" resolution="300" resUnits="pixels/inch" mode="CMYK Color" bitDepth="8-bit" colorProfile="Working CMYK" flattenLayers="true"/>'+ 

  '<thumbnail place="across first" cols="' + myColumns + '" rows="' + myRows + '" bestFit="true" useAutospacing="true" horz="0.014 in" vert="0.014 in"/>'+ 

  '<caption enabled="true">'+ 

   '<font name="ArialMT" size="9.5"/>'+ 

  '</caption>'+ 

'</ContactSheetIISettings>' ); 

    var idMsge = charIDToTypeID( "Msge" ); 

    desc1.putString( idMsge, "Settings for Contact Sheet II" );

executeAction( id, desc1, DialogModes.NO); 

}

//Hides the ContactSheet II dialog window, but in order to work it's necessary to edit Photoshop's ContactSheet.jsx

$.setenv("NoUI", true);

createContactSheet(myFileList); 

But it doesn't work. Any ideas are more than welcomed.

Thanks.

This topic has been closed for replies.

4 replies

JJMack
Community Expert
Community Expert
May 20, 2019

Actually using Contac Sheet's dialog you can build up a list of files.  There are also many other settings the can also be set.  You script is running Contact sheet script and not having Contact sheet display its dialog executeAction( id, desc1, DialogModes.NO); so many default or remembered last setting will be used.  When you use that script.  Here  is Contact Sheets dialog where I building up a image file list. Images I select. Use menu File>Automate>Contavt Sheet II... instead of  using menu File>Scripts>Your Script name....

JJMack
Participating Frequently
May 20, 2019

My reason of trying to make a script instead of the default PS ContactSheet script is because I need to automatically compute the number or rows/columns which will be dependent of the number of files I'll select.

JJMack
Community Expert
Community Expert
May 20, 2019

Now you have completely lost me that script is not doing any calculations related to rows and columns  and is not setting any of the Contact Sheet II setting for rows or columns though you did added  variables into the function for them.  However they are undefuned in the scriop.  You changed the function one parameted vaiable name to filesName.  The script does not retrieve any file image size information for use in calulations?  Your script create an array "var aFile = selectFile(true); " and passes that array aFile to your createContactSheet its first File path is is used to set folderName  contact sheet will most likely process all the image files in the first files folder for Contact sheets Dialog is suppressed DialogModes.NO,  It does will not dynamically update its dialog so you can add  more folders and files, It will most likely just processes the folder passed  in folderName. Actually the function may just through a scripting error for I do not see the varable you added into the function code "myCsolumns" and "myRows"  set they seem to be undefined.

No rarameter varianle is set

//Set ContactSheet II parameters 

function createContactSheet(filesName){  

var id = stringIDToTypeID( "0B71D221-F8CE-11d2-B21B-0008C75B322C" );  

    var desc1 = new ActionDescriptor();  

    var idCSIISettings = stringIDToTypeID( "CSIISettings" ); 

    var folderName=filesName[0].parent.fsName; 

    desc1.putString( idCSIISettings, '<ContactSheetIISettings>'+  

  '<source imageSource="Files" path="'+ folderName +'" includeSubfolders="false" groupImages="false"/>'+  

  '<document units="cm" width="41" height="27.7" resolution="300" resUnits="pixels/inch" mode="CMYK Color" bitDepth="8-bit" colorProfile="Working CMYK" flattenLayers="true"/>'+  

  '<thumbnail place="across first" cols="' + myCsolumns + '" rows="' + myRows + '" bestFit="true" useAutospacing="true" horz="0.014 in" vert="0.014 in"/>'+  

  '<caption enabled="true">'+  

  '<font name="ArialMT" size="9.5"/>'+  

  '</caption>'+  

'</ContactSheetIISettings>' );  

    var idMsge = charIDToTypeID( "Msge" );  

    desc1.putString( idMsge, "Settings for Contact Sheet II" ); 

executeAction( id, desc1, DialogModes.NO);  

JJMack
JJMack
Community Expert
Community Expert
May 20, 2019

The script you posted is using Photoshop's Script contact sheet to create contact sheets.  Photoshop Contact sheet script work on  a folder or folder tree and creates contact sheets for the image in a folder or a set of folders a file system tree containing image files.  If you want to make contact sheets for a selection of files you need to code that process, You can not use Photoshop Contact sheet script to create your contact sheets.

If you are not able to coder then all you can do is use script other write.   If you can not find a script that does what you want you need to learn how to code or heir a programmer to write a script for you.

JJMack
Participating Frequently
May 20, 2019

Now I'm really confused.

So you're saying that even though I have the option to choose Files as an input source, I can't script that option? That's really disappointing since I really need a script to make a contact sheet with a the number or rows/columns based on a customised algorithm from a selection of files.

JJMack
Community Expert
Community Expert
May 20, 2019

The function you created from action manager code requires a Folder name not a list of files,

//Set ContactSheet II parameters

function createContactSheet(folderName){

var id = stringIDToTypeID( "0B71D221-F8CE-11d2-B21B-0008C75B322C" );

    var desc1 = new ActionDescriptor();

    var idCSIISettings = stringIDToTypeID( "CSIISettings" );

    desc1.putString( idCSIISettings, '<ContactSheetIISettings>'+

  '<source imageSource="Folder" path="'+ folderName +'" includeSubfolders="false" groupImages="false"/>'+

  '<document units="cm" width="41" height="27.7" resolution="300" resUnits="pixels/inch" mode="CMYK Color" bitDepth="8-bit" colorProfile="Working CMYK" flattenLayers="true"/>'+

  '<thumbnail place="across first" cols="' + myColumns + '" rows="' + myRows + '" bestFit="true" useAutospacing="true" horz="0.014 in" vert="0.014 in"/>'+

  '<caption enabled="true">'+

   '<font name="ArialMT" size="9.5"/>'+

  '</caption>'+

'</ContactSheetIISettings>' );

    var idMsge = charIDToTypeID( "Msge" );

    desc1.putString( idMsge, "Settings for Contact Sheet II" );

executeAction( id, desc1, DialogModes.NO);

}

you tried to change it to use file names  but only change the variable and never change the code to use that variable the code needs a folder name  not a file list

//Set ContactSheet II parameters

function createContactSheet(filesName){

var id = stringIDToTypeID( "0B71D221-F8CE-11d2-B21B-0008C75B322C" );

    var desc1 = new ActionDescriptor();

    var idCSIISettings = stringIDToTypeID( "CSIISettings" );

    var folderName=filesName[0].parent.fsName;

    desc1.putString( idCSIISettings, '<ContactSheetIISettings>'+

  '<source imageSource="Files" path="'+ folderName +'" includeSubfolders="false" groupImages="false"/>'+

  '<document units="cm" width="41" height="27.7" resolution="300" resUnits="pixels/inch" mode="CMYK Color" bitDepth="8-bit" colorProfile="Working CMYK" flattenLayers="true"/>'+

  '<thumbnail place="across first" cols="' + myColumns + '" rows="' + myRows + '" bestFit="true" useAutospacing="true" horz="0.014 in" vert="0.014 in"/>'+

  '<caption enabled="true">'+

   '<font name="ArialMT" size="9.5"/>'+

  '</caption>'+

'</ContactSheetIISettings>' );

    var idMsge = charIDToTypeID( "Msge" );

    desc1.putString( idMsge, "Settings for Contact Sheet II" );

executeAction( id, desc1, DialogModes.NO);

}

Contact Sheet Script requires a folder of files not a list of files.  Your script would need to process the file list and create a contact sheet something like I do in my Paste Image Roll script or do exactly what contact sheet does steal contact sheet script code to layout your list of files.

In my PasteImageRoll sctipy you will see your openDialog statement and how it would be filtered if none image files get included in the list.   The does cause a slight problem. The Canvas size calculated may be larger than needed but the extra canvas can be trimmed after the images are pasted in.

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

JJMack
Participating Frequently
May 20, 2019

But it has an option to choose files instead of a folder so how can I script that?

I used Event Listener to record when I manually use the PS ContactSheet and pick some files from a folder and the log looks like this:

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

(function 0B71D221-F8CE-11d2-B21B-0008C75B322C_07055807113647()

    {

    try {

        var d = new ActionDescriptor();

        d.putString(stringIDToTypeID("CSIISettings"), "<ContactSheetIISettings>\n  <source imageSource=\"Files\" path=\"/Users/me/Desktop/tests\" includeSubfolders=\"true\" groupImages=\"false\"/>\n  <document units=\"cm\" width=\"41\" height=\"28.7\" resolution=\"300\" resUnits=\"pixels/cm\" mode=\"RGB Color\" bitDepth=\"8-bit\" colorProfile=\"sRGB IEC61966-2.1\" flattenLayers=\"true\"/>\n  <thumbnail place=\"across first\" cols=\"8\" rows=\"3\" bestFit=\"true\" useAutospacing=\"true\" horz=\"0.035 cm\" vert=\"0.035 cm\"/>\n  <caption enabled=\"true\">\n    <font name=\"MinionPro-Regular\" size=\"11\"/>\n  </caption>\n</ContactSheetIISettings>");

        d.putString(stringIDToTypeID("message"), "Settings for Contact Sheet II");

        executeAction(stringIDToTypeID("0B71D221-F8CE-11d2-B21B-0008C75B322C"), d, DialogModes.NO);

        }

    catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }

    }

)();

JJMack
Community Expert
Community Expert
May 20, 2019

You are passing contact sheet the file list array.  You are passing contact sheet a files list like you did in the first script where you used getfiles to get all the files in a folder.  The getfiles part most likely should has filtered the list to only gets Image files.

You may have a problem  with the second script on a Mac getting the list using openDialog .  In the open dialog you pass three parameters The dialog title, filetype filter and a true/false multiple file option.   I believe the filter parameter is a window only one.     So on mac you would need different or additional filtering code. to Filter image files type for mac users may be able to select any file types.  Your are passing myFilelist which may contain files that are not images files on a mac. You could get all the imaged file in the list into a different array and pass that array to Contact sheet.   I believe scripts that I have written create file list with code like yours  but my script process the file list and only process file types the match the opebDialog filter list incase the users is running on a mac.  You may also want to check that you have a file list that the user did not cancel out of the dialog.

I may filter a file list like this:

if (file instanceof File && !file.name.match(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|psd|tif|tiff|jpg|jpe|jpeg|png|bmp|)$/i) ) continue;

you also create a myFolder variable "var myFolder = myFileList[0].path"  and never uset it?

JJMack
JJMack
Community Expert
Community Expert
May 20, 2019

Reading the manual it look like on a mac you can include a filter function in an openDialog all parameters are optional....

JJMack