Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script help Works as javascript but not photoshop

Contributor ,
Apr 28, 2016 Apr 28, 2016

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

TOPICS
Actions and scripting
387
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Apr 29, 2016 Apr 29, 2016

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

...
Translate
Adobe
Community Expert ,
Apr 28, 2016 Apr 28, 2016

Have you tried the $.evalFile() command? Is there a reason you don't want to combine the scripts into one, and make life easier?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 29, 2016 Apr 29, 2016

Hi I am trying to combine the 2 scripts. but I get errors  with this line

  1. var BorderIncrease = itemTable.filter(function ( obj ) {  
  2.     return obj.itemType === "BW"; //BW is to be replaced with ItemType

I am very inexperienced with script, but what does $.evalFile() command mean/do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 29, 2016 Apr 29, 2016

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;

};

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 29, 2016 Apr 29, 2016
LATEST

Perfect Many thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines