Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

How To Draw a JPG Using Python and RhinoScriptSyntax

$
0
0

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 ()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles