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
jojo
Level I

select current data table

Hello,

I am using a small jmp_addin to add spec limits info to selected columns.  Anyways, the problem I run into is that whenever I run it, it always grabs the latest data table that was open, even if I am running the addin from a different window...is there a way to highlight to the jmp_addin that I am trying to run script from the selected data table?  I thought currentdatatable would do this, but again it seems it always works on latest data table open, and sometimes I need to change/add specs to an already open table...

 

Thanks in advance!

 

 

dt = currentdatatable();
table=list("Spec1", "Spec2", "Spec3" );
r = Column Dialog(
Spec = Col List( "Columns to add Spec" ),
v list ("Select Product Spec Table", rb = Combo Box( table()))
);
 
dtedc = open("C:\myData\ADDIN\Spec Limit\"||table[r["rb"]]||".jmp",invisible);
 
for ( i=1, i<=N Items(r["Spec"]),i++,
for (j=1, j<= nrows(dtedc), j++,
if(as Name(r["Spec"]) == as Name(dtedc:Parameter),
 
  Eval(
  Substitute(
  Expr(
Column(dt, r["Spec"]) << set property("spec limits",
  {LSL( l), Target( t ), USL( u ), Show Limits(1)}
  )
  ),
  Expr( l ), dtedc:LSL,
  Expr( t ), dtedc:Target,
  Expr( u ), dtedc:USL
  )
 
);
 
  );
);
);
 
close(dtedc, nosave);

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: select current data table

I just came across this old question that, unfortunately, never got a response.

 

Current Data Table() should return a reference to the active data table window. I'm not sure why it isn't in your case.

 

However, a more reliable method is to prompt the user to choose from the open data tables.

 

Here's a small function that prompts with a list of data tables and returns the choice made by the user.

choose_data_table=function({},
list = {};

For( i = 1, i <= N Table(), i++,
	list[i] = Data Table( i ) << get name
);

win = New Window( "Select a data table", << Modal,
	hb = H List Box(
		Panel Box( "Choose a data table",
			dt = List Box(
				list,
				max selected( 1 ),
				chosen = Data Table( (dt << get selected)[1] );
				show (chosen);
			)
		),

	)
);
chosen);

Use it like this:

dt=choose_data_table(); 
show(dt);

 

-Jeff

View solution in original post

9 REPLIES 9
Jeff_Perkinson
Community Manager Community Manager

Re: select current data table

I just came across this old question that, unfortunately, never got a response.

 

Current Data Table() should return a reference to the active data table window. I'm not sure why it isn't in your case.

 

However, a more reliable method is to prompt the user to choose from the open data tables.

 

Here's a small function that prompts with a list of data tables and returns the choice made by the user.

choose_data_table=function({},
list = {};

For( i = 1, i <= N Table(), i++,
	list[i] = Data Table( i ) << get name
);

win = New Window( "Select a data table", << Modal,
	hb = H List Box(
		Panel Box( "Choose a data table",
			dt = List Box(
				list,
				max selected( 1 ),
				chosen = Data Table( (dt << get selected)[1] );
				show (chosen);
			)
		),

	)
);
chosen);

Use it like this:

dt=choose_data_table(); 
show(dt);

 

-Jeff
cassadeus
Level II

Re: select current data table

Hi @Jeff_Perkinson ,

 

I am trying to employ this in a fairly simple module that formats data markers. It worked great when I initially set the script, but since has been inconsistently working. Are there any ideas why it would be so? The Column titles and values are reliable.

 

 

dt=choose_data_table();
show(dt);
dt << Select Where( :Pad Summary == "Overload" );
dt << Colors( 22 );
dt << Markers( 11 );
dt << Select Where( :Pad Summary == "Curve Error" );
dt << Colors( 27 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Detected" );
dt << Colors( 4 );
dt << Markers( 12 );
dt << Select Where( :Pad Summary == "Position Misalign" );
dt << Colors( 3 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Negative (w/ Misalign)" );
dt << Colors( 1 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Negative" );
dt << Colors( 1 );
dt << Markers( 0 );
dt << Select Where( :Pad Summary == "Disconnect" );
dt << Colors( 0 );
dt << Markers( 9 );
dt << Select Where( :Pad Summary == "High CP Current" );
dt << Colors( 56 );
dt << Markers( 24 );

 

 

Thank you 

 

 

Jeff_Perkinson
Community Manager Community Manager

Re: select current data table

I think we're going to need more information about what "inconsistently working" means. Can you provide more detail?

-Jeff
cassadeus
Level II

Re: select current data table

Yeah, I'll try. Sorry I am pretty new and not formally trained in any scripting, which is probably obvious. I added the data table selector into this script rather than use:

 

dt = Current Data Table();

 

and ensuring that the current data table was the table I wanted to reformat. When I first implemented the Choose data table function it worked like a charm, and created a prompt from which to select the desired table. I sent it too a colleague to use, and it didn't work for him, despite verifying that the script was unchanged. I opened the saved script and it didn't work for me either. So I alternated between previous methods of formatting, and back to the choose data table method and it worked again. Later it no longer did.

 

I don't really have a good technical explanation for the inconsistency, or what changed between successful and unsuccessful attempts. As far as I can tell nothing specifically did. I hack these things together, so there are definitely some fundamental principles that I am lacking, such as clearing or designating preferences or symbols. Maybe the issue is outside the scope of a short forum post?

 

Thanks either way

 

 

txnelson
Super User

Re: select current data table

what errors are you getting in the log?

Jim
cassadeus
Level II

Re: select current data table

@txnelson

Thank you for asking. I hadn't considered checking the log. It says:

Name Unresolved: choose_data_table in access or evaluation of 'choose_data_table' , choose_data_table() /*###*/

In the following script, error marked by /*###*/
dt = choose_data_table() /*###*/;
Show( dt );
dt << Select Where( :Pad Summary == "Overload" );
dt << Colors( 22 );
dt << Markers( 11 );
dt << Select Where( :Pad Summary == "Curve Error" );
dt << Colors( 27 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Detected" );
dt << Colors( 4 );
dt << Markers( 12 );
dt << Select Where( :Pad Summary == "Position Misalign" );
dt << Colors( 3 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Negative (w/ Misalign)" );
dt << Colors( 1 );
dt << Markers( 2 );
dt << Select Where( :Pad Summary == "Negative" );
dt << Colors( 1 );
dt << Markers( 0 );
dt << Select Where( :Pad Summary == "Disconnect" );
dt << Colors( 0 );
dt << Markers( 9 );
dt << Select Where( :Pad Summary == "High CP Current" );
dt << Colors( 56 );
dt << Markers( 24 );
dt << Select Where( :Run Status == "Invalid" );
dt << Markers( 4 );
txnelson
Super User

Re: select current data table

When I saw the line

dt = choose_data_table();

I assumed that you had a function somewhere earlier in your code that let you pick the data table to run on.  But if you do not, then I suggest you change the line to:

dt = current data table();

and try running your code

Jim
cassadeus
Level II

Re: select current data table

Yeah, that works. I was just hoping for a method that would prompt users to select a table since we often have many open at once. And relying on awareness of the various users for their current data table hasn't worked well in the past. was just hoping to have a method of prompting users to specify. But this will have to do.

 

pmroz
Super User

Re: select current data table

If you put the choose_data_table function definition at the top of your code it will work.