我在一家大型时装公司工作,我们有一个旧的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 );
最佳答案
欢迎使用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
关于javascript - Momentis(PLM)的Photoshop脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39647788/