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
mcudzinovic
Level II

What script code do I need to automatically add a background image to a graph box?

What script code do I need to automatically add a background image to a graph box?

Here's a sample of a simple script I use to create a graph box:

win = New Window( "Map",
	Graph Box(
		Frame Size(600, 600),
		X Scale(0, 1252),
		Y Scale(0, 1252),
		Pen Color("white"),
		Line( {10, 10}, {10, 1200} );
		Line( {600, 10}, {600, 1200} );
		Line( {1200, 10}, {1200, 1200} );
	)
);

After I run the above script I can drag and drop a jpg image into the background and manipulate it (rotate, change size, change transparency, etc.).

What code do I need to automate adding the jpg image background as part of the script?

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: What script code do I need to automatically add a background image to a graph box?

You are really close. The main issue, as you suspect, is the report message. The report message is sent to a platform to get the display box tree. The GraphBox is a displaybox tree, not a platform. There are also some minor tweaks to the positioning parameters (and I played with some other parameters too.) The top,left and bottom,right positions are specified in the same coordinates as the axes.

win = New Window( "Map",
	gb=Graph Box(
		Frame Size(600, 600),
		X Scale(0, 1252),
		Y Scale(0, 1252),
		Pen Color("red"),
		Line( {10, 10}, {10, 1200} );
		Line( {600, 10}, {600, 1200} );
		Line( {1200, 10}, {1200, 1200} );
	)
);



fb1 = gb[Frame Box( 1 )];
fb1 << add Image(
	Open(
		Convert File Path(
			"$SAMPLE_IMAGES/black rhino footprint.jpg"
		)
	),
	Transparency( 0.5 ),
	Rotate( 45 ),
	Bounds(
		Top( 800 ),Left( 100 ),
		Bottom( 100 ),Right( 800 )
	),
	//SetSize( {300, 210} )
);

background picture positioned and rotatedbackground picture positioned and rotated

Craige

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: What script code do I need to automatically add a background image to a graph box?

What you will need to do is to paste the background image into the Frame Box() of your Graph Box().  Below is the example taken directly from the Scripting Index illustrating how to do this

     Help==>Scripting Index==>FrameBox==>Paste Background Image

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Animals.jmp" );
op = Overlay Plot(
	X( :subject ),
	Y( :miles ),
	Separate Axes( 1 )
);
opr1 = op << report;
opr2 = opr1 << Clone Box;
opr1 << append( opr2 );
fb1 = opr1[Frame Box( 1 )];
fb1 << Add Image(
	Open(
		Convert File Path(
			"$SAMPLE_IMAGES/black rhino footprint.jpg"
		)
	),
	Transparency( 0.9 ),
	Rotate( 90 ),
	Bounds(
		Left( 0.135416666666667 ),
		Right( 3.26041666666667 ),
		Top( 11.8333333333333 ),
		Bottom( -1 )
	),
	SetSize( {300, 210} )
);
fb1 << Copy Picture;
fb2 = opr2[Frame Box( 1 )];
fb2 << Paste Background Image;
Jim
Craige_Hales
Super User

Re: What script code do I need to automatically add a background image to a graph box?

You might get some ideas from this post about how the frame's segment layering can be controlled to move your picture in front of or behind your data. It is possible to have a map, data points, and images, and get them in the order you need.

Craige
mcudzinovic
Level II

Re: What script code do I need to automatically add a background image to a graph box?

xnelson,

I cannot figure out how to use your suggestion. Looking in my Help ==> Scripting Index I could not find your referenced "Help==>Scripting Index==>FrameBox==>Paste Background Image". I tried the following script made from my sample script and trying to apply your suggestion:

// Here's my original script:
win = New Window( "Map",
	Graph Box(
		Frame Size(600, 600),
		X Scale(0, 1252),
		Y Scale(0, 1252),
		Pen Color("white"),
		Line( {10, 10}, {10, 1200} );
		Line( {600, 10}, {600, 1200} );
		Line( {1200, 10}, {1200, 1200} );
	)
);

// And here's what I added based on your suggestion:
opr1 = win << report;
fb1 = opr1[Frame Box( 1 )];
fb1 << Add Image(
	Open(
		Convert File Path(
			"$SAMPLE_IMAGES/black rhino footprint.jpg"
		)
	),
	Transparency( 0.9 ),
	Rotate( 90 ),
	Bounds(
		Left( 0.135416666666667 ),
		Right( 3.26041666666667 ),
		Top( 11.8333333333333 ),
		Bottom( -1 )
	),
	SetSize( {300, 210} )
);

When I run the script I get an error message saying:
"The display box 'EvalContextBox' does not recognize the message 'report'; perhaps you mean one of these:  <<Set Report Title <<Reshow <<set horizontal <<get horizontal <<Parent <<Prepend <<Get RTF <<Save RTF <<Get Web Support <<Border <<Set Property <<Get Property <<Get Property List <<Get Properties <<Set Property <<Get Property <<Get Property List <<Get Properties."

I looked through the Scripting Index and found a reference to "report", but with syntax "y= Report( platform object)". So I tried replacing the line "opr1 = win << report;" with "opr1 = Report(win)". That got rid of the first error message, but now I get an error message "Send Expects Scriptable Object in access or evaluation of 'Send' , fb1 <<  /*###*/Add Image(".

I thought maybe I need to refer to the Graph Box itself instead of the New Window, so I tried the script:

win = New Window( "Map",
	gb= Graph Box(
		Frame Size(600, 600),
		X Scale(0, 1252),
		Y Scale(0, 1252),
		Pen Color("white"),
		Line( {10, 10}, {10, 1200} );
		Line( {600, 10}, {600, 1200} );
		Line( {1200, 10}, {1200, 1200} );
	)
);

opr1 = Report( gb );
fb1 = opr1[Frame Box( 1 )];
fb1 << Add Image(
	Open(
		Convert File Path(
			"$SAMPLE_IMAGES/black rhino footprint.jpg"
		)
	),
	Transparency( 0.9 ),
	Rotate( 90 ),
	Bounds(
		Left( 0.135416666666667 ),
		Right( 3.26041666666667 ),
		Top( 11.8333333333333 ),
		Bottom( -1 )
	),
	SetSize( {300, 210} )
);

(Note I tried the syntax "opr1 = gb << report" first, but it gave me the original "report" error.) I still have a "Send Expects Scriptable Object in access or evaluation of 'Send' , fb1 <<  /*###*/Add Image(" error.

What am I doing wrong?

Also, is there a way to embed the image into the script? Multiple people will be running the script so a specific reference to an image location will not scale easily. For example, instead of using "Open" when I Add Image, can I use "Set Blob( Char To Blob())"?

Craige_Hales
Super User

Re: What script code do I need to automatically add a background image to a graph box?

You are really close. The main issue, as you suspect, is the report message. The report message is sent to a platform to get the display box tree. The GraphBox is a displaybox tree, not a platform. There are also some minor tweaks to the positioning parameters (and I played with some other parameters too.) The top,left and bottom,right positions are specified in the same coordinates as the axes.

win = New Window( "Map",
	gb=Graph Box(
		Frame Size(600, 600),
		X Scale(0, 1252),
		Y Scale(0, 1252),
		Pen Color("red"),
		Line( {10, 10}, {10, 1200} );
		Line( {600, 10}, {600, 1200} );
		Line( {1200, 10}, {1200, 1200} );
	)
);



fb1 = gb[Frame Box( 1 )];
fb1 << add Image(
	Open(
		Convert File Path(
			"$SAMPLE_IMAGES/black rhino footprint.jpg"
		)
	),
	Transparency( 0.5 ),
	Rotate( 45 ),
	Bounds(
		Top( 800 ),Left( 100 ),
		Bottom( 100 ),Right( 800 )
	),
	//SetSize( {300, 210} )
);

background picture positioned and rotatedbackground picture positioned and rotated

Craige
txnelson
Super User

Re: What script code do I need to automatically add a background image to a graph box?

Here is an image of the reference to Paste Background Image

paste background.PNG

 

Jim
mcudzinovic
Level II

Re: What script code do I need to automatically add a background image to a graph box?

Thanks for the image. I am able to find it now! I was accidentally searching under "Functions" instead of "All Categories."