Copy link to clipboard
Copied
I'm trying to get these 2 scripts to work together.
this runs in Photoshop fine.
#target photoshop
if (app.documents.length > 0) {
var myDocument = activeDocument;
var fileNameNoExtension = myDocument.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length--;
}
fileNameNoExtension = fileNameNoExtension.join(".");
var BrandID = fileNameNoExtension.substr(0,4);
var ItemType = fileNameNoExtension.substr(4,2);
alert(ItemType)
}
The alert is just for a test run, A file named EM10NW021231.jpg returns the "ItemType" as "NW"
This part of the script runs as javascript
var itemTable = [
{itemType: "RI", BorderIncrease:"180"},
{itemType: "NW", BorderIncrease:"115"},
{itemType: "CL", BorderIncrease:"115"},
{itemType: "BW", BorderIncrease:"120"},
{itemType: "SC", BorderIncrease:"120"},
{itemType: "ER", BorderIncrease:"150"},
{itemType: "WW", BorderIncrease:"140"},
{itemType: "WA", BorderIncrease:"140"},
{itemType: "HR", BorderIncrease:"140"},
{itemType: "JM", BorderIncrease:"100"},
{itemType: "NA", BorderIncrease:"100"}
];
var BorderIncrease = itemTable.filter(function ( obj ) {
return obj.itemType === "BW"; //BW is to be replaced with ItemType
})[0];
alert(BorderIncrease.BorderIncrease);
How can I link these together where line 16 is to replace the "BW" with the ItemType from the first script?
Many Thanks
Matt
Please try this.
...#target photoshop
if (app.documents.length > 0) {
var myDocument = activeDocument;
var fileNameNoExtension = myDocument.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length--;
}
fileNameNoExtension = fileNameNoExtension.join(".");
var BrandID = fileNameNoExtension.substr(0,4);
var ItemType = fileNameNoExtension.substr(4,2);
alert(ItemTy
Copy link to clipboard
Copied
Have you tried the $.evalFile() command? Is there a reason you don't want to combine the scripts into one, and make life easier?
Copy link to clipboard
Copied
Hi I am trying to combine the 2 scripts. but I get errors with this line
I am very inexperienced with script, but what does $.evalFile() command mean/do?
Copy link to clipboard
Copied
Please try this.
#target photoshop
if (app.documents.length > 0) {
var myDocument = activeDocument;
var fileNameNoExtension = myDocument.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length--;
}
fileNameNoExtension = fileNameNoExtension.join(".");
var BrandID = fileNameNoExtension.substr(0,4);
var ItemType = fileNameNoExtension.substr(4,2);
alert(ItemType)
var itemTable = [
{itemType: "RI", BorderIncrease:"180"},
{itemType: "NW", BorderIncrease:"115"},
{itemType: "CL", BorderIncrease:"115"},
{itemType: "BW", BorderIncrease:"120"},
{itemType: "SC", BorderIncrease:"120"},
{itemType: "ER", BorderIncrease:"150"},
{itemType: "WW", BorderIncrease:"140"},
{itemType: "WA", BorderIncrease:"140"},
{itemType: "HR", BorderIncrease:"140"},
{itemType: "JM", BorderIncrease:"100"},
{itemType: "NA", BorderIncrease:"100"}
];
var BI = BorderIncrease(itemTable, ItemType );
alert(BI);
function BorderIncrease(Arr, Item){
for(var z in Arr){
if(Arr
.itemType === Item){ return Arr
.BorderIncrease; }
}
return 0;
};
};
Copy link to clipboard
Copied
Perfect Many thanks!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now