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

To Show an alert box

Explorer ,
Oct 21, 2016 Oct 21, 2016

Copy link to clipboard

Copied

hi,

is there any possibility to show an alert box in photoshop with the information taken excel sheet values

for example in my active document there is an layer group named [Coffee] using this name as reference the script should go to excel worksheet by using vlookup function and search for coffee in column B2 and return with price value of the product mention in excel sheet.

so the alerbox will provide information of the product price in photoshop itself

please help me in this

TOPICS
Actions and scripting

Views

2.2K

Translate

Translate

Report

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
Adobe
Community Expert ,
Oct 21, 2016 Oct 21, 2016

Copy link to clipboard

Copied

I don't know if you would be able to read a excel file directly, but you could save out the file as either a CSV or XML and then you could read the file and get the values.

Votes

Translate

Translate

Report

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
Explorer ,
Oct 21, 2016 Oct 21, 2016

Copy link to clipboard

Copied

thanks for the reply how to do with .csv file because i am having that version of my file also

Votes

Translate

Translate

Report

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
Explorer ,
Oct 22, 2016 Oct 22, 2016

Copy link to clipboard

Copied

But How to Reference the values of .CSV file into .jsx to get values

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 22, 2016 Oct 22, 2016

Copy link to clipboard

Copied

I'm not sure how you're cvs file is set up, but I made one like this"

I set up a PS file like this:

The csv file is called script-test.csv and is on my desktop. I selected the group coffee and  ran this script

#target photoshop

var doc = activeDocument

var gp = doc.activeLayer

var csvFile = new File('~/desktop/script-test.csv')

var fileInfo = readTextFile (csvFile)

var foods = fileInfo.split('\n')[0].split(',')

var price = fileInfo.split('\n')[1].split(',')

for (var i=0;i<foods.length;i++){

    if(foods==gp.name){

        doc.activeLayer = gp.layers[0]

        doc.activeLayer.textItem.contents = price

        }

    }

function readTextFile(textFile){

        textFile.encoding = "UTF8";

        textFile.lineFeed = "unix";

        textFile.open("r", "TEXT", "????");

        var str = textFile.read();

        textFile.close();

        return str

    }

I then got this result:

Votes

Translate

Translate

Report

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
Enthusiast ,
Oct 22, 2016 Oct 22, 2016

Copy link to clipboard

Copied

I don't know what exactly should be result of your work, but seem to that you could be insterested in bult-in Photoshop function which can generate images from CSV files:

Tutorial : : Creating Data-Driven Graphics in Photoshop - YouTube

Votes

Translate

Translate

Report

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
Explorer ,
Oct 22, 2016 Oct 22, 2016

Copy link to clipboard

Copied

i am getting error on the variable price line and how to implement the alert method to popup the details in the .csv file and display it  in alertbox

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 22, 2016 Oct 22, 2016

Copy link to clipboard

Copied

If you want just an alert box, replace lines 12 and 13 in my above code with:

alert(price)

Votes

Translate

Translate

Report

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
Explorer ,
Oct 23, 2016 Oct 23, 2016

Copy link to clipboard

Copied

it does nothing can you just tell me how should the .csv excel file need to be or what are all order elements should place in excel file

Votes

Translate

Translate

Report

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
Community Expert ,
Oct 23, 2016 Oct 23, 2016

Copy link to clipboard

Copied

It would be better for you to show how your csv file is set up. I just did one as an example, as I wasn't sure what you're was like.

Votes

Translate

Translate

Report

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
Explorer ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

screen shot of csv.JPG

Votes

Translate

Translate

Report

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
Explorer ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

the alert box is the thing i needed but its not reading the text file anyone tell me how to read the text file values.

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

In my first script I posted, I had the values in my excel file going the other direction that you have in yours. So I changed that and created a cvs file from this:

I made a PSD file with those three foods as layer names:

Then I modified the script to read the values in that direction:

#target photoshop 

var doc = activeDocument 

var gp = doc.activeLayer 

 

var csvFile = new File('~/desktop/script-test.csv') 

var fileInfo = readTextFile (csvFile) 

var foods = fileInfo.split('\n')

for (var i=0;i<foods.length;i++){ 

    if(foods.split(',')[0]==gp.name){ 

        alert(foods.split(',')[1])

        } 

    } 

 

function readTextFile(textFile){ 

        textFile.encoding = "UTF8"; 

        textFile.lineFeed = "unix"; 

        textFile.open("r", "TEXT", "????"); 

        var str = textFile.read(); 

        textFile.close(); 

        return str 

    } 

This is what I get with the almond layer selected and running the script:

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

Hi Vfxvenkat98​,

the answer is given in the post #5 by

But your own csv is not consistent or a wrong example

Votes

Translate

Translate

Report

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
Explorer ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

Thank you very much Chuck Uebele 

But one more thing  just want to know if the script will work in on a .csv file like this setup

because in future my setup file will be like this

The script should take Values only with PRODUCT in A1, and TYPE in C1 and show the rest of the details as above.

thanks a lot

Votes

Translate

Translate

Report

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
Explorer ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

FIle setup.JPG

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 13, 2016 Nov 13, 2016

Copy link to clipboard

Copied

In line 11 of the code I just posted that is the line for the alert and contains the info on what to display:

alert(foods.split(',')[1]) 

The array "foods" contains the entire line in the cvs file. each entry is separated by the comma. So when you use split using the comma, it splits that array entry into another array of just that line. So you can get each column by changing the number at the end. Arrays are numbered starting at 0. So in the above line, there is a 1, which denotes the second column. In your example, you would use 1 for the stock entries, 2 for the type, and 3 for the price. How you want to display that is up to you.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 16, 2016 Nov 16, 2016

Copy link to clipboard

Copied

that worked but what if no data found in the text file or .csv i wanted it to show an alert of no data found and even i tried

else loop to show another alert box of "No data Found" but it iterates through the Whole sheet and continuously showing the error at multiple times.

Is there any solution for that.

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 16, 2016 Nov 16, 2016

Copy link to clipboard

Copied

put the code in a try/catch block, so it doesn't throw an error and allows you to control what happens:

try{alert(foods.split(',')[1])  }

catch(e){alert('There is no data')}

Votes

Translate

Translate

Report

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
Explorer ,
Nov 16, 2016 Nov 16, 2016

Copy link to clipboard

Copied

i tried these block with in for loop but not working for me

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 16, 2016 Nov 16, 2016

Copy link to clipboard

Copied

You're going to have to post some of your code, so we can see what is going wrong.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 17, 2016 Nov 17, 2016

Copy link to clipboard

Copied

  1. #target photoshop   
  2. var doc = activeDocument   
  3. var gp = doc.activeLayer   
  4. try {  
  5. var csvFile = new File('~/desktop/script-test.csv')   
  6. var fileInfo = readTextFile (csvFile)   
  7. var foods = fileInfo.split('\n'
  8.  
  9. for (var i=0;i<foods.length;i++){   
  10.     if(foods.split(',')[0]==gp.name){   
  11.         alert(foods.split(',')[1]) 
  12.         }   
  13.     }   
  14. }
  15. catch(e){
  16. alert"Type not found")
  17. }
  18. function readTextFile(textFile){   
  19.         textFile.encoding = "UTF8";   
  20.         textFile.lineFeed = "unix";   
  21.         textFile.open("r", "TEXT", "????");   
  22.         var str = textFile.read();   
  23.         textFile.close();   
  24.         return str   
  25.     }   

Votes

Translate

Translate

Report

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
Explorer ,
Nov 17, 2016 Nov 17, 2016

Copy link to clipboard

Copied

and also i want to i know how to attach the .csv file from a network share drive.

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 17, 2016 Nov 17, 2016

Copy link to clipboard

Copied

LATEST

You have an issue with your splitting the csv file. You're adding spaces around the comma, there shouldn't be any spaces:

.split(',')

NOT

.split(' , ')

As far as using a CSV file from a network drive, you just need to enter the full path to the file on the network. Don't used a mapped path, but the actual path.

Votes

Translate

Translate

Report

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