简体   繁体   中英

Photoshop Script for Momentis (PLM)

I work at a large fashion company, and we have an old PLM system that requires us to create 2 types of JPGs, one normal and one thumbnail-sized. Then our vendors require us to send them a PDF with a certain output preset.

I have managed to get a script that does mostly what I need that I will post below, but I can't seem to get the filenames just how I would like it, I want it to remove the old extension when saving the new files, everything I have tried has been for not.

Also, I would like the PSD to save back in the original location again that it is currently active document opened in photoshop.

Any guidance would be greatly appreciated.

// 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 );

Welcome to StackOverflow.

Just looking at the code, I think the extension is getting added after using the history state or a save. To avoid that remove the extension prior to saving.

Try using this function on 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM