File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1111
1212import os , sys , re
1313import inspect
14+ import subprocess
15+ import tempfile
1416
1517openscad_builtins = [
1618 # 2D primitives
@@ -602,6 +604,34 @@ def __mul__(self, x):
602604 '''
603605 return intersection ()(self , x )
604606
607+ def _repr_png_ (self ):
608+ '''
609+ Allow rich clients such as the IPython Notebook, to display the current
610+ OpenSCAD rendering of this object.
611+ '''
612+ png_data = None
613+ tmp = tempfile .NamedTemporaryFile (suffix = ".scad" , delete = False )
614+ tmp_png = tempfile .NamedTemporaryFile (suffix = ".png" , delete = False )
615+ try :
616+ scad_text = scad_render (self ).encode ("utf-8" )
617+ tmp .write (scad_text )
618+ tmp .close ()
619+ tmp_png .close ()
620+ subprocess .Popen ([
621+ "openscad" ,
622+ "--preview" ,
623+ "-o" , tmp_png .name ,
624+ tmp .name
625+ ]).communicate ()
626+
627+ with open (tmp_png .name , "rb" ) as png :
628+ png_data = png .read ()
629+ finally :
630+ os .unlink (tmp .name )
631+ os .unlink (tmp_png .name )
632+
633+ return png_data
634+
605635
606636class IncludedOpenSCADObject (OpenSCADObject ):
607637
You can’t perform that action at this time.
0 commit comments