cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
bobmorrane
Level V

Set MAp Role via script

Hello,

 

I am making a script to help beginners set some parameters in a data table, such as table variables and map roles.

The issue is when I set the map role, the file path is not recorded in the column properties

 

path = pick file ();

dt0:my_column << set property ("Map Role", Map Role ("Shape Name Use" (path), "My_column") ) ) ;

Any ideas what causes this ?

 

~~Bob~~
8 REPLIES 8
bobmorrane
Level V

Re: Set MAp Role via script

Ok, after fiddling with this for a while, I see where the problem lies :

 

file paths in Windows look like this  C:\user\file.txt

 

When you extract a path in jmp using pick file (), it converts it to "C:/user/file.txt". I guess this is because JMP considers '\' to be a special character. The weird thing is, in other JSL instructions, you can just use the JMP syntax for file paths but for some reason, Map Role uses the normal Windows syntax.

 

 

Now my question is : is there a simple way to convert a JMP file path into a Windows file path ? Something that would avoid the need to write it like this :

 

"C:\!\user\!\file.txt"

 

Alternatively, a script that could access the column properties directly and open the prompt t ochoose a file in the map role pane would be useful too.

 

Thanks

~~Bob~~
bobmorrane
Level V

Re: Set MAp Role via script

Ok it looks like I found a solution to this :

 

 

dt= open (pick file (), invisible ) ;

path = dt<< get path;

 

dt<<close ;

show (path);

This seems to solve it  

~~Bob~~

Re: Set MAp Role via script

Also, I think that the argument with the path is a named argument, not a string, so it looks like this:

 

dt0:my_column << Set Property ( "Map Role", Map Role( Shape Name Use( path ), "My_column" ) ) ) ;

 

BTW, JMP uses the POSIX path format by default, not the Windows format. But usually it will automatically convert or you can explicitly call the built-in function to convert between the two formats.

bobmorrane
Level V

Re: Set MAp Role via script

thanks @Mark_Bailey ,

 

I learnt something here. I didn't know what Posix was

 

Searching for POSIX in the Scripting index, I found the conversion function :

 

path = pick file () ; 

converted_path= Convert File Path (path, windows) ; 

Compared to using the <<get path message, this saves the opening of the table.

 

~~Bob~~
bobmorrane
Level V

Re: Set MAp Role via script

So I do I manage to set this property from a text string ?

 

You said this is " a named argument, not a string ". What does this mean ? I guess this is a downside of JSL, the system being so simple and flexible, users don't know the exact nature of what they are manipulating

 

I tried the following syntaxes to no avail :

dt0:my_column << Set Property ( "Map Role", Map Role( Shape Name Use(Eval( path) ), "My_column" ) );

dt0:my_column << Set Property ( "Map Role", Map Role( Shape Name Use(Expr( path) ), "My_column" ) );

Eval Expr (dt0:my_column << Set Property ( "Map Role", Map Role( Shape Name Use(Expr( path) ), "My_column" ) ) );
~~Bob~~

Re: Set MAp Role via script

It is simple. Here are examples of different arguments.

 

Literal argument, numeric or character string:

x = Sqrt( 5 );

x = Num( "5" );

Variable argument:

x = 5;
y = Sqrt( x );

Named argument:

dt << Bivariate( Y( :weight ), X( :height ), Fit Line );

The last example includes named arguments (Y, X, and Fit Line) and literal arguments (:weight and :height). Your original code enclosed the Shape Name Use() named argument in character string delimiters, which made it a character string argument.

Re: Set MAp Role via script

That route is a bit round-about and unnecessary. See this function.

bobmorrane
Level V

Re: Set MAp Role via script

Ok, finally my script works

 

For some reason, when I wrote :

dt0:my_column << set property ("Map Role", Map Role (Shape Name Use (path, "my_column" ) ) ;

It wouldn't transfer the string contained in the variable path into the column property. It still wouldn't work when I tried to use Eval(path) and other workarounds. I'm guessing JSL doesn't support evaluating variables Inside this message.

 

So here is the workaround I found :

 

My_expression = Eval Expr ( dt0:my_column << set property ("Map Role", Map Role (Shape Name Use (Expr(path), "my_column" ) ) );

Eval (My_expression); 

And this finally does the trick!

 

The step to convert the path from posix to Windows was not necesary in the end, as  the column property accepts both formats.

 

 

 

~~Bob~~