cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Polyabc
Level II

Using variables in path name

Hello,

Please forgive me if this is a trivial question, I do not have much experience working with JSL. 

 

I am trying to add a picture to the hover label using JSL code, and want to define the picture path using a variable. I have a folder of pictures, and want them to be called using a variable in my table.

 

For example, my pictures are labeled 1 to 100, and I have a column in my table called "picture number". I want to be able to call them, like this:

 

PictureBox(Open("c:/iris/"picture number" .jpg", jpg));

 

is this possible?

 

Many thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
nascif_jmp
Level VI

Re: Using variables in path name

You might want to check this thread. They had the same use case. The thread contains many script examples that you should find useful.

Hover label 

 

View solution in original post

10 REPLIES 10
Craige_Hales
Super User

Re: Using variables in path name

Yes, some variation of this:

 

img << saveimage( "f:/path/x" || Char( imagenumber ) || ".png", "png" );

x is the prefix before the number and is not required by the operating system.

Craige
Polyabc
Level II

Re: Using variables in path name

thanks! i'll give it a try.

Polyabc
Level II

Re: Using variables in path name

Using a specific picture number works fine, but I cannot insert a variable name (the variable column is "picture number") to this path, for example, the following does not work. Any idea how to fix this?

 

PictureBox(Open("c:/iris/" || :picture number|| ".jpg", jpg));

 

jthi
Super User

Re: Using variables in path name

If you check out the example Hover Label Editor gives for Picture Graphlet

// Example:
//   Graph Builder(Variables(Y(local:_measurements[1])), Elements(Histogram(Y)))
// Example: 
//   PictureBox(Open("c:/iris/" || local:_Species || ".jpg", jpg));

the syntax seems be a bit special. Maybe it would work with something like this:

PictureBox(Open("c:/iris/" || char(local:_picture number)|| ".jpg", jpg));
-Jarmo
Craige_Hales
Super User

Re: Using variables in path name

Check the log for messages. One or more of the following might help.

Build the path name in a variable and print it to the log, then pass the variable to open.

Add quotation marks around the 2nd parameter to open.

Add the data table scope before the column name.

Add a row number subscript after the column name.

 

edit: use the char() function to convert numeric to character!

 

filename = "c:/iris/" || char(dt:picture number[1]) || ".jpg";
show(filename);
PictureBox(Open( filename, "jpg"));

 

Craige
nascif_jmp
Level VI

Re: Using variables in path name

You might want to check this thread. They had the same use case. The thread contains many script examples that you should find useful.

Hover label 

 

Polyabc
Level II

Re: Using variables in path name

Thanks for the responses.

 

I have a follow up question. I want the hover label to get the file address from a column. My column has the address itself, for example, the text in my Colum (named PicAdress) is "c:/iris/picNumber.jpg" .

 

However, I cannot get the hovel label to accept this variable. i have tried using:

 

PictureBox(Open(local:_PicAdress, jpg))

 

with no success.

 

When I simply enter the address in the column there is no problem.

 

PictureBox(Open("c:/iris/" || local:_PicAdress || ".jpg", jpg))

 

Any advice?

 

 

jthi
Super User

Re: Using variables in path name

Try checking out the log to see what errors you are getting. Most likely something like this: "The namespace "local_" is not defined in access or evaluation of 'local_:PicAdress'".

 

Try out something like this:

Picture Box(Open(Column("PicAdress")[local:_firstRow],jpg))

More info possibly from:  

 

Edit:

I added example script. It will create couple of files (10 by default) to $TEMP (and attempt to delete them on window close) and create window with two graph builders:

  1. First will build path from the data in graph builder using this idea: PictureBox(Open("c:/iris/" || local:_PicAdress || ".jpg", jpg))
  2. Second is using only the row information from graph builder and getting data based on row from datatable Picture Box(Open(Column("PicAdress")[local:_firstRow],jpg))
-Jarmo
Polyabc
Level II

Re: Using variables in path name

Thanks a lot, this works great.