我在一家大型时装公司工作,我们有一个旧的PLM系统,要求我们创建两种类型的JPG,一种是普通的,一种是缩略图。然后我们的供应商要求我们向他们发送带有特定输出预设的PDF。
我设法得到一个脚本,主要完成我需要的脚本,我将在下面发布,但我似乎无法获得文件名,我想要它,我希望它删除旧的扩展名时保存新文件,我尝试过的一切都不是。
另外,我希望PSD再次保存在原始位置,它是当前在photoshop中打开的活动文档。
非常感谢任何指导。
// Saves the current state of the open document, so we can revert to it later to re-save the image to the correct document format
var savedState = app.activeDocument.activeHistoryState;
var sourceDoc = app.activeDocument.name;
// Saves Open Document as PDF to server location
var idsave = charIDToTypeID( "save" );
var desc60 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc61 = new ActionDescriptor();
var idpdfPresetFilename = stringIDToTypeID( "pdfPresetFilename" );
desc61.putString( idpdfPresetFilename, """GYMDESIGN""" );
var idpdfOutputConditionIdentifier = stringIDToTypeID( "pdfOutputConditionIdentifier" );
desc61.putString( idpdfOutputConditionIdentifier, '""""""' );
var idpdfRegistryName = stringIDToTypeID( "pdfRegistryName" );
desc61.putString( idpdfRegistryName, '""""""' );
var idPhtP = charIDToTypeID( "PhtP" );
desc60.putObject( idAs, idPhtP, desc61 );
var idIn = charIDToTypeID( "In " );
desc60.putPath( idIn, new File( "/our server location/"+ sourceDoc + ".pdf") );
var idDocI = charIDToTypeID( "DocI" );
desc60.putInteger( idDocI, 320 );
var idLwCs = charIDToTypeID( "LwCs" );
desc60.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc60.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc60, DialogModes.NO );
// Saves Open Document as JPG to server location
var idsave = charIDToTypeID( "save" );
var desc68 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc69 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc69.putInteger( idEQlt, 12 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc69.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc68.putObject( idAs, idJPEG, desc69 );
var idIn = charIDToTypeID( "In " );
desc68.putPath( idIn, new File("/our server location/" + sourceDoc + ".jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc68.putInteger( idDocI, 320 );
var idLwCs = charIDToTypeID( "LwCs" );
desc68.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc68.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc68, DialogModes.NO );
// Scales Open Document to 25% resolution
var idImgS = charIDToTypeID( "ImgS" );
var desc76 = new ActionDescriptor();
var idRslt = charIDToTypeID( "Rslt" );
var idRsl = charIDToTypeID( "#Rsl" );
desc76.putUnitDouble( idRslt, idRsl, 25.000000 );
var idscaleStyles = stringIDToTypeID( "scaleStyles" );
desc76.putBoolean( idscaleStyles, true );
var idCnsP = charIDToTypeID( "CnsP" );
desc76.putBoolean( idCnsP, true );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idautomaticInterpolation = stringIDToTypeID( "automaticInterpolation" );
desc76.putEnumerated( idIntr, idIntp, idautomaticInterpolation );
executeAction( idImgS, desc76, DialogModes.NO );
// Saves scaled Open Document to thumbnail size, and to server location
var idsave = charIDToTypeID( "save" );
var desc81 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc82 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc82.putInteger( idEQlt, 5 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc82.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc81.putObject( idAs, idJPEG, desc82 );
var idIn = charIDToTypeID( "In " );
desc81.putPath( idIn, new File( "/our server location/" + sourceDoc + "_thumb" + ".jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc81.putInteger( idDocI, 320 );
var idLwCs = charIDToTypeID( "LwCs" );
desc81.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc81.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc81, DialogModes.NO );
//Restore save state from earlier in the document
app.activeDocument.activeHistoryState = savedState;
// Resaves as PSD file to original location
var idsave = charIDToTypeID( "save" );
var desc88 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc89 = new ActionDescriptor();
var idPhtthree = charIDToTypeID( "Pht3" );
desc88.putObject( idAs, idPhtthree, desc89 );
var idIn = charIDToTypeID( "In " );
desc88.putPath( idIn, new File( "original location" + sourceDoc + ".psd" ) );
var idDocI = charIDToTypeID( "DocI" );
desc88.putInteger( idDocI, 320 );
var idLwCs = charIDToTypeID( "LwCs" );
desc88.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc88.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc88, DialogModes.NO );
答案 0 :(得分:0)
欢迎使用StackOverflow。
只是查看代码,我认为在使用历史状态或保存后会添加扩展。为避免在保存之前删除扩展名。
尝试在sourcedoc上使用此功能
function removeImageExtension (s)
{
return s.substring(0, s.lastIndexOf("."));
}
sourceDoc = "/our server location/" + sourceDoc + ".jpg";
sourceDoc = removeImageExtension(sourceDoc);
// /our server location/sourceDoc
sourceDoc ="/our server location/" + sourceDoc + "_thumb" + ".jpg"
// /our server location/sourceDoc_thumb.jpg