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
miguello
Level VI

How to reference Outline Box from within red triangle menu without using variables

Here's a reworked example from Scripting Index:

Names Default To Here( 1 );

	ob = Outline Box( "Picker",
		{"Copy picture", ob << Copy Picture()},
		H List Box( Text Box( "Label:" ), teb = Text Edit Box( Char( 213 ) ) )
	);

New Window( "Example",
ob
);

It adds a menu item in the red triangle menu that would copy the picture of this box to the buffer.

Script works just fine.

 

My question is: what if I create my Outline Boxes dynamically, and I don't have a variable assigned to it.

How do I reference this Outline Box without variable? Something using keywords "this" or "self".

Something like this on the second box:

Names Default To Here( 1 );
vb = V List Box(
	ob = Outline Box( "Picker",
		{"Copy picture", ob << Copy Picture()},
		H List Box( Text Box( "Label:" ), teb = Text Edit Box( Char( 213 ) ) )
	),
Outline Box( "Picker",
		{"Copy picture", this << Copy Picture()},
		H List Box( Text Box( "Label number 2:" ), teb = Text Edit Box( Char( 213 ) ) )
	);
);




New Window( "Example",
vb
);

There are good examples in Scripting Index for Set Function on number of Display Boxes:

Names Default To Here( 1 );
New Window( "Example",
	Button Box( "press me", <<setFunction( Function( {thisBox}, thisBox << setButtonName( "thanks" ) ) ) )
);

But in this case we're not setting function, we're setting script, and this syntaxis doesn't work.

 

So, how do I accomplish this?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to reference Outline Box from within red triangle menu without using variables

I don't think you have functionality like that for outline box menu scripts so you have to use something else. Three okeish options come to my mind:

  • Evaluate the reference
  • Use Window scope
  • Use Box scope
Names Default To Here(1);

context_example = Context Box(
	box:ob1 = Outline Box("Picker",
		{"Copy picture1", box:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(213))
		)
	)
);

eval_example = Outline Box("Picker",
	H List Box(
		Text Box("Label:"), 
		teb = Text Edit Box(Char(612))
	)
);
Eval(EvalExpr(
	eval_example << Set Menu Script(
		{"Copy Picture3", Expr(eval_example) << Copy Picture()}
	);	
));

nw = New Window("Example", 
	context_example,
	window:ob1 = Outline Box("Picker",
		{"Copy picture2", window:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(451))
		)
	),
	eval_example
);
-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: How to reference Outline Box from within red triangle menu without using variables

I don't think you have functionality like that for outline box menu scripts so you have to use something else. Three okeish options come to my mind:

  • Evaluate the reference
  • Use Window scope
  • Use Box scope
Names Default To Here(1);

context_example = Context Box(
	box:ob1 = Outline Box("Picker",
		{"Copy picture1", box:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(213))
		)
	)
);

eval_example = Outline Box("Picker",
	H List Box(
		Text Box("Label:"), 
		teb = Text Edit Box(Char(612))
	)
);
Eval(EvalExpr(
	eval_example << Set Menu Script(
		{"Copy Picture3", Expr(eval_example) << Copy Picture()}
	);	
));

nw = New Window("Example", 
	context_example,
	window:ob1 = Outline Box("Picker",
		{"Copy picture2", window:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(451))
		)
	),
	eval_example
);
-Jarmo
miguello
Level VI

Re: How to reference Outline Box from within red triangle menu without using variables

Looks like Eval and Context box ways are working in my case, Window - does not.

Here is what I used to check, it imitates dynamic creating of Outline Boxes:

 

Names Default To Here(1);
vb = V List Box();
context_example = Context Box(
	box:ob1 = Outline Box("Context1",
		{"Copy picture1", box:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(213))
		)
	)
);
vb << Append (context_example);
context_example = Context Box(
	box:ob1 = Outline Box("Context2",
		{"Copy picture1", box:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(213))
		)
	)
);
vb << Append (context_example);


eval_example = Outline Box("Eval1",
	H List Box(
		Text Box("Label:"), 
		teb = Text Edit Box(Char(612))
	)
);
Eval(EvalExpr(
	eval_example << Set Menu Script(
		{"Copy Picture3", Expr(eval_example) << Copy Picture()}
	);	
));
vb << Append (eval_example);
eval_example = Outline Box("Eval2",
	H List Box(
		Text Box("Label:"), 
		teb = Text Edit Box(Char(612))
	)
);
Eval(EvalExpr(
	eval_example << Set Menu Script(
		{"Copy Picture3", Expr(eval_example) << Copy Picture()}
	);	
));
vb << Append (eval_example);


nw = New Window("Example", 
	window:ob1 = Outline Box("Window1",
		{"Copy picture2", window:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(451))
		)
	),
	window:ob1 = Outline Box("Window2",
		{"Copy picture2", window:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box(Char(451))
		)
	),
	vb
);

In case of Window in both cases of Window1 and Window2 it copies picture of Window2 box.

hogi
Level XII

Re: How to reference Outline Box from within red triangle menu without using variables

You can use a variable multiple times in a script to assign different values. At the end, the variable will contain the last value. This holds for

 

x=5;
x=7;
show(x);

and for :ob1.
The solution  use 2 different variables to define references to 2 different objects:

nw = New Window("Example", 
	window:ob1 = Outline Box("Window1",
		{"Copy picture", window:ob1 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box("#1")
		)
	),
	window:ob2 = Outline Box("Window2",
		{"Copy picture", window:ob2 << Copy Picture()},
		H List Box(
			Text Box("Label:"), 
			teb = Text Edit Box("#2")
		)
	)
);

 

jthi
Super User

Re: How to reference Outline Box from within red triangle menu without using variables

You are overwriting your references in your window example (use window:ob1 and window:ob2 for example). This doesn't happen within context box as box: seems to remember in which context box it belongs to. Depending on your "real" use case and application, the evaluation method is usually the most robust but all of these have their pros and cons (as does just using direct references).

-Jarmo
hogi
Level XII

Re: How to reference Outline Box from within red triangle menu without using variables

Hard to find more details - even for LLMs:

hogi_0-1735471803768.png