Skip to content

Instantly share code, notes, and snippets.

@sbaer
Last active July 16, 2020 23:11
Show Gist options
  • Save sbaer/bebd530d103a56cdd0076156af66f54b to your computer and use it in GitHub Desktop.
Save sbaer/bebd530d103a56cdd0076156af66f54b to your computer and use it in GitHub Desktop.
import Rhino
import System.Drawing
import scriptcontext
import rhinoscriptsyntax as rs
class CustomConduit(Rhino.Display.DisplayConduit):
def __init__(self):
url = 'https://gist.githubusercontent.com/sbaer/bebd530d103a56cdd0076156af66f54b/raw/a92efce9ef85fd09316a42afcd899bd0e2d19b15/greetings.png'
self.image = Rhino.Display.DisplayBitmap.Load(url)
def DrawForeground(self, e):
size = e.Viewport.Size
center = Rhino.Geometry.Point2d(size.Width*0.5,size.Height*0.5)
imageSize = self.image.Size
scaleX = size.Width / imageSize.Width
scaleY = size.Height / imageSize.Height
scale = scaleX
if scaleY > scaleX: scale = scaleY
width = scale * imageSize.Width
height = scale * imageSize.Height
e.Display.DrawSprite(self.image, center, width, height)
if __name__== "__main__":
conduit = CustomConduit()
conduit.Enabled = True
scriptcontext.doc.Views.Redraw()
rs.GetString("Pausing for user input")
conduit.Enabled = False
scriptcontext.doc.Views.Redraw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment