File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -602,6 +602,34 @@ def __mul__(self, x):
602602 '''
603603 return intersection ()(self , x )
604604
605+ def _repr_png_ (self ):
606+ '''
607+ Allow rich clients such as the IPython Notebook, to display the current
608+ OpenSCAD rendering of this object.
609+ '''
610+ png_data = None
611+ tmp = tempfile .NamedTemporaryFile (suffix = ".scad" , delete = False )
612+ tmp_png = tempfile .NamedTemporaryFile (suffix = ".png" , delete = False )
613+ try :
614+ scad_text = scad_render (self ).encode ("utf-8" )
615+ tmp .write (scad_text )
616+ tmp .close ()
617+ tmp_png .close ()
618+ subprocess .Popen ([
619+ "openscad" ,
620+ "--preview" ,
621+ "-o" , tmp_png .name ,
622+ tmp .name
623+ ]).communicate ()
624+
625+ with open (tmp_png .name , "rb" ) as png :
626+ png_data = png .read ()
627+ finally :
628+ os .unlink (tmp .name )
629+ os .unlink (tmp_png .name )
630+
631+ return png_data
632+
605633
606634class IncludedOpenSCADObject (OpenSCADObject ):
607635
You can’t perform that action at this time.
0 commit comments