Article View: adobe.photoshop.scripting
Article #1967Re: Saving all open files as jpeg
From: Barbu_Bogdan
Date: Thu, 01 Jul 2004 18:30
Date: Thu, 01 Jul 2004 18:30
210 lines
5339 bytes
5339 bytes
Hi!
To do that I used something like this:
........................................
SPErr SaveFiles()
{
int32 numDocuments;
SPErr error = kSPNoError;
DescriptorTypeID typeID = 0;
sPSActionControl->StringIDToTypeID("Getting Document Info", &typeID);
error = PIUGetInfo(classApplication, keyNumberOfDocuments, &numDocuments, NULL);
if (error)
{
goto returnError;
}
if (numDocuments > 0)
for (int32 counter = 1; counter <= numDocuments; counter++) {
(void) PIUSelectByIndex(classDocument, counter);
char *filePath;
char buffer[80];
char dir[]=PHOTO_SAVE_DIR;
char photo[]=PHOTO_NAME;
char ext[]=PHOTO_EXT;
_itoa(counter, buffer, 10);
filePath = createFileName(dir, photo, buffer, ext);
error = SaveFile(filePath);
if (error)
{
counter = numDocuments+1;
goto returnError;
}
}
returnError:
return error;
}
...............................
SPErr SaveFile(char * filePath)
{
SPErr error = kSPNoError;
PIActionDescriptor result = NULL;
PIActionDescriptor desc = NULL;
PIActionDescriptor JPGDescriptor = NULL;
Handle tempAlias = NULL;
error = sPSActionDescriptor->Make(&desc);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->Make(&JPGDescriptor);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutString(desc, keyTitle, filePath);
if(error)
{
goto returnError;
}
#if Macintosh
NewAliasMinimalFromFullPath(strlen(filePath), filePath, nil, nil, &(AliasHandle)tempAlias);
#else
tempAlias = sPSHandle->New(strlen(filePath)+1);
if (tempAlias != NULL)
{
GlobalLock(tempAlias);
strncpy(*tempAlias, filePath, strlen(filePath)+1);
GlobalUnlock(tempAlias);
}
#endif
error = sPSActionDescriptor->PutEnumerated(JPGDescriptor, keyPreview, typeEPSPreview, enumTIFF);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutEnumerated(JPGDescriptor,keyDepth,typeDepth,enum8BitsPerPixel);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutEnumerated(JPGDescriptor, keyEncoding, typeEncoding, enumJPEG);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutBoolean(JPGDescriptor, keyHalftoneScreen, true);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutBoolean(JPGDescriptor, keyTransferFunction, true);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutBoolean(JPGDescriptor, keyColorManagement, true);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutObject(desc, keyAs, classJPEGFormat, JPGDescriptor);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutAlias(desc, keyIn, tempAlias);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutBoolean(desc, keyCopy, true);
if(error)
{
goto returnError;
}
error = sPSActionDescriptor->PutBoolean(desc, keyLowerCase, true);
if(error)
{
goto returnError;
}
error = sPSActionControl->Play(&result, eventSave, desc, plugInDialogSilent);
if(error)
{
goto returnError;
}
returnError:
if (desc != NULL)
{
error = sPSActionDescriptor->Free(desc);
}
if (JPGDescriptor != NULL)
{
error = sPSActionDescriptor->Free(JPGDescriptor);
}
if (result != NULL)
{
error = sPSActionDescriptor->Free(result);
}
#if Macintosh
if (tempAlias != NULL)
{
DisposeHandle( tempAlias );
}
#else
if (tempAlias != NULL)
{
sPSHandle->Dispose(tempAlias);
}
#endif
return error;
}
---------------------------------------------------------
char *createFileName(char dir[], char name[], char index[], char ext[])
{
char *fileName, *filePath;
fileName = strcat(name, index);
fileName = strcat(dir, fileName);
filePath = strcat(fileName, ext);
return filePath;
}
......................................
and somewhere into a header I have
#define PHOTO_SAVE_DIR "c:\\photos\\";
#define PHOTO_NAME "photo";
#define PHOTO_EXT ".jpg";
................
When I called the SaveFiles() method it saved all the opened files in the directory "c:\photos" with the names : "photo1.jpg", photo2.jpg",../.
If you want to save the files with the name from Photoshop application, in the SaveFiles() you must replace
char buffer[80];
char dir[]=PHOTO_SAVE_DIR;
char photo[]=PHOTO_NAME;
char ext[]=PHOTO_EXT;
_itoa(counter, buffer, 10);
filePath = createFileName(dir, photo, buffer, ext);
with
sPSActionDescriptor->GetStringLength(result, keyTitle, &lung);
sPSActionDescriptor->GetString(result, keyTitle, filePath, lung+1);
Technical Details
Message-ID:
<3bb4dd9c.0@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<3bb4dd9c.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,e983e4eaa16343e X-Google-Attributes: gidf5839,public X-Google-Language: ENGLISH,ASCII-7-bit From: Barbu_Bogdan@adobeforums.com Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.photoshop.scripting Subject: Re: Saving all open files as jpeg Message-ID: <3bb4dd9c.0@webx.la2eafNXanI> Date: Thu, 1 Jul 2004 11:30:01 -0700 References: <3bb4dd9c.-1@webx.la2eafNXanI> Lines: 224 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit