How To Draw a JPG Using Python and RhinoScriptSyntax

I have created an image (.jpg) which I would liike to draw on the screen using Python, not through the Picture command. There’s more to the project which requires this part to be done in Python using RhinoScriptSyntax. In particular, the end result is printed to an Epilog laser cutter where the image is engraved on the surface of a sheet of acrylic and the border cuts out each of the 18 individual pieces.

So far I have the following code with the variable “image” drawn using Image and ImageDraw from PIL

import Rhino as rh
import rhinoscriptsyntax as rs
import scriptcontext as sc

from PIL import Image, ImageDraw

image = Image.new("RGB", (width, height), white)
draw = ImageDraw.Draw(image)   

# Code to draw the square image into the variable "image"
# This code work fine and allows me to save the image in a file as a JPG.
...

hatched_layer_index = sc.doc.Layers.Find (“Layer 01”, True)
current_layer_index = sc.doc.ActiveDoc.Layers.CurrentLayerIndex

# The border is Layer 0 which is cut through the entire sheet whereas
#   the image is engraved on the surface (Layer 1).
# How do I draw the contents of "image" using rhinoscript (rs) into Layer 1?






sc.doc.ActiveDoc.Layers.SetCurrentLayerIndex (current_layer_index, True);
rs.Redraw ()

Does the jpeg need to be some kind of native Rhino object for the laser cutter to do its thing from Layer 1, or does the jpeg literally only need to be displayed on screen, and that could be in any application?

You might be able to use the DrawSprite method. Here’s an example running in GhPython:

But I’m sure one can also implement the method in a “regular” Rhino Python script. And welcome on board :slight_smile:

The JPG is a byproduct of this code:

For some reason the rest of my message was lost:

On 9/25/2025 4:39 AM, James Parrott via McNeel Forum wrote:

[James_Parrott] James Parrott https://discourse.mcneel.com/u/james_parrott
September 25

Does the jpeg need to be some kind of native Rhino object for the laser cutter to do its thing from Layer 1, or does the jpeg literally only need to be displayed on screen, and that could be in any application?

The JPG is a byproduct of this code:

from PIL import Image, ImageDraw

image = Image.new(“RGB”, (width + 2mar, height + 2mar), white)
draw = ImageDraw.Draw(image)

which then draws various black rectangles using draw.rectangle(…) and then I save it as a JPG using

filename = filepath+“SquareHole.jpg”
image.save(filename)

Ignoring the save as a JPG, it is this “image” that I want to draw on the Rhino 6 screen into a particular Layer so as to distinguish it from the Layer that cuts out the square acrylic coaster.

I hope that helps.

Thanks. I’m not going to be able to try anything in Rhino 6. But if all else fails with the IronPython APIs, I would do the operations manually, and note down the Rhino Commands in the window just under the pull down menus, then try a script that inputs those strings into rs.command