2016-09-22 91 views
1

我在一家大型時裝公司工作,我們有一箇舊的PLM系統,需要我們創建2種類型的JPG,一種是正常的,另一種是縮略圖。然後我們的供應商要求我們向他們發送一個具有特定輸出預設的PDF。Momentis(PLM)的Photoshop腳本

我已經設法得到一個腳本,主要是我需要的,我會在下面發佈,但我似乎無法得到文件名,只是我希望它,我希望它在保存時刪除舊的擴展名新的文件,我所嘗試過的一切都不是。

此外,我想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

歡迎來到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