Copy link to clipboard
Copied
Hello, I'm trying to use a smartObject replace script found on the web, but I don't want to use the Dialog to select the files I would like to use an hardcoded location in the script.
I tried everything and have no idea how to use the file as a hardcoded location
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// JPG Options;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
// Check if layer is SmartObject;
if (theLayer.kind != "LayerKind.SMARTOBJECT") {
alert("selected layer is not a smart object")
} else {
// Select Files;
if ($.os.search(/windows/i) != -1) {
// var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg;*.png;*.pdf", true)
var theFiles = File("directory/smartObjectFile.jpg")
} else {
var theFiles = File.openDialog("please select files", getFiles, true)
};
if (theFiles) {
for (var m = 0; m < theFiles.length; m++) {
// Replace SmartObject
theLayer = replaceContents(theFiles[m], theLayer);
// Save JPG
myDocument.saveAs((new File("NewMadeFile.jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
}
}
}
};
Your code is not complete so i could not test it, the definition for replaceContents method is missing. Try the following, change the path of the file that you want to replace with, in the code.
if (app.documents.length > 0)
{
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// JPG Options;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedC
...
Copy link to clipboard
Copied
Your code is not complete so i could not test it, the definition for replaceContents method is missing. Try the following, change the path of the file that you want to replace with, in the code.
if (app.documents.length > 0)
{
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// JPG Options;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
// Check if layer is SmartObject;
if (theLayer.kind != "LayerKind.SMARTOBJECT")
alert("selected layer is not a smart object")
else
{
var file = File("/Users/manan/Downloads/383822.pdf")
theLayer = replaceContents(file, theLayer);
myDocument.saveAs((new File("NewMadeFile.jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
}
};
-Manan
Copy link to clipboard
Copied
Great, that worked and I see what I was doing wrong, I kept expecting an Array of files