Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Reading the manual it look like on a mac you can include a filter function in an openDialog all parameters are optional....
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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); } }
}
)();
Copy link to clipboard
Copied
Herer a thread I found for you Re: pre-scan
Copy link to clipboard
Copied
Thank you, but since I'm not a coder I don't know how to correctly implement that.
I changed the first part, but I got the same (non) result.
#target Photoshop;
var aFile = selectFile(true);
function selectFile (multi) {
if (multi == true) {var theString = "please select files"}
else {var theString = "please select one file"};
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}
else {var theFiles = File.openDialog (theString, getFiles, multi)};
////// filter files for mac //////
function getFiles (theFile) {
if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {
return true
};
};
return theFiles
};
//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);
}
//Hides the ContactSheet II dialog window, but in order to work it's necessary to edit Photoshop's ContactSheet.jsx
$.setenv("NoUI", true);
createContactSheet(aFile);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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....
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
If you want to use contact sheet II do do what you want to do you need to use its dialog dynamically build the file list using its dialog buttons. Once you get the list built make the calculation you want and set the dialog setting you calculated and click OK to generated the contact sheets. I have no Idea as what calculations you want to make. Or what information is need to make your calculations.
Copy link to clipboard
Copied
Ok, there seem to be a lot of misunderstandings here.
I'm sorry I wasn't very clear with my request, I'll try to clarify as best as I can.
1. The goal of the script is to process thousands of files on a daily basis. Doing that manually is an incredible waste of time, hence the need of a script to automate that process.
2. My script has over 500 lines of code, but I posted only the relevant parts, the part that I have a problem with. How I calculate the number of rows and columns is irrelevant because that's not the problem. And since all the parameters used to create the contact sheet are defined by the script and there is no manual input there's no need to show the ContactSheet window, the process needs to be streamlined.
3. I've made a similar script that worked fine using all the images from a chosen folder, so my problem now is how to get it to work by choosing files instead of a folder. And it's got to do with createContactSheet parameter. As you noticed, before it was a folder, now it's an array of files and obviously the array is not recognised as a valid parameter for the function. But I have no idea how to tell createContactSheet to use that array of files. That's the only issue.
Copy link to clipboard
Copied
I believe you can most likely script what you want to do, But I do not believe you can use Contact Sheet II script to create the contact sheets you want. If you look at the way Contact Sheet II script is designed. Its like two scripts in one. One script is a process that creates a file list the can be edited folder of files added, files selected files added, files removed, bridge files selections added, and the file list can be sorted. Once this list is the your liking you click OK and then the second script Process kicks in and Process the file list and creates the contacts sheets.
You script creates a File list yes but turns off Contact Sheet II Dialog so its not interactive. You do pass the file list you created to your function. However it look like your function just passes the folder the first file in your file list is in to Contact Sheet II, in the Contact Sheet II settings. If your script set the variable for columns and rows you showed I would think Contact Sheet would create its file list to include all the files in passed folder then move on to phase two create contact sheets. It may not be possible to pass a file list to Contact Sheet. Files may be able to be a file list. I doe not actually know JavaScript programing I hack at it.The first interactive Phase in Contact Sheets II in the script seems designed to built the file list that is use as input image files for the Contac sheets. Your function passes a folder to Contact Sheet II in Contact Sheets II settings.
//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);
}
Contact Sheet II JavaScript Code is above my pay grade I cans understand some of the processing being done however, some of the code to me is more like trying to decode an some lost old writing. The key seems to be the ability to know the variactions that can be used for typeInputSource
Copy link to clipboard
Copied
Well, I think I should just try to start from scratch and write code that will place the selected images in the document instead of trying to make the ContactSheet II script do that.
Thank you for your time and for trying to help me with this.
Copy link to clipboard
Copied
That is what I did when I wrote PasteImageRol.jsx I wanted to tile image resized to fill a particular image tile sized and mask off any excess resized image. I only want to create one document not many contact sheets. So I created a dialog to let the user define the document width and max height. Define the Tile size and spacing between tile and document border size. The problem I have is most likely have problems on a mac. I should change the code to the file list function I found for you. I may do that today. But will not be able to test the code till I visit my son to see if he has an old mac with Photoshop on it. He now has a Microsoft Studio 2.