# OpenSCAD example, ported by Michael Mlivoncic #import sys #sys.path.append("O:/BlenderStuff") import blenderscad # import imp # imp.reload(blenderscad) # imp.reload(blenderscad.core) # imp.reload(blenderscad.primitives) # imp.reload(blenderscad.impexp) blenderscad.initns( globals() ) # try to add BlenderSCAD names to current namespace .. as if they would be in this file... ## Clear the open .blend file!!! #clearAllObjects() ###### End of Header ############################################################################## ## example012.stl is Mblock.stl, (c) 2009 Will Langford ## licensed under the Creative Commons - GNU GPL license. ## http://www.thingiverse.com/thing:753 import os # use folder where the .dxf fuile is located os.chdir("O:/BlenderStuff/examples") difference(
# This block helps during developmentas it reloads the blenderscad modules which are already present # and may have changed... # can be commented out or removed if you do not modify blenderscad libs during this blender session. import imp; import sys rel = ['blenderscad','blenderscad.math', 'blenderscad.core', 'blenderscad.primitives','blenderscad.impexp', 'blenderscad.shapes'] for mo in rel: if mo in sys.modules.keys(): print ('reloading: '+mo+' -> '+ sys.modules[mo].__file__) imp.reload(sys.modules[mo]) ######################## import blenderscad #from blenderscad.shapes import * # optional blenderscad.initns(globals()) # to avoid prefixing all calls, we make "aliases" in current namespace ## Clear the open .blend file!!! clearAllObjects() ############################### import time import datetime st = datetime.datetime.fromtimestamp( time.time() ).strftime('%Y-%m-%d %H:%M:%S') echo ("BEGIN ", st) ############################## # NO OpenSCAD thing, but nice alternative to union(). It preserves the objects and # therefore different colors. However, need to rework subsequent modifiers?
# can be commented out or removed if you do not modify blenderscad libs during this blender session. import imp; import sys rel = ['blenderscad','blenderscad.math', 'blenderscad.core', 'blenderscad.primitives','blenderscad.impexp', 'blenderscad.shapes'] for mo in rel: if mo in sys.modules.keys(): print ('reloading: '+mo+' -> '+ sys.modules[mo].__file__) imp.reload(sys.modules[mo]) ######################## import blenderscad import bpy #bpy.ops.wm.console_toggle() blenderscad.initns( globals() ) # try to add BlenderSCAD names to current namespace .. as if they would be in this file... ## Clear the open .blend file!!! clearAllObjects() ###### Timestamp ############################################################################## import time import datetime st = datetime.datetime.fromtimestamp( time.time() ).strftime('%Y-%m-%d %H:%M:%S') echo ("BEGIN", st) ###### End of Header ############################################################################## def example002():
import imp import sys rel = [ 'blenderscad', 'blenderscad.math', 'blenderscad.core', 'blenderscad.primitives', 'blenderscad.impexp', 'blenderscad.shapes' ] for mo in rel: if mo in sys.modules.keys(): print('reloading: ' + mo + ' -> ' + sys.modules[mo].__file__) imp.reload(sys.modules[mo]) ######################## import blenderscad #from blenderscad.shapes import * # optional blenderscad.initns(globals( )) # to avoid prefixing all calls, we make "aliases" in current namespace ## Clear the open .blend file!!! clearAllObjects() ############################### import time import datetime st = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') echo("BEGIN ", st) ############################## # NO OpenSCAD thing, but nice alternative to union(). It preserves the objects and # therefore different colors. However, need to rework subsequent modifiers?
import bpy import blenderscad ## init blenderscad and its namespace blenderscad.initns(globals()) ## we can now begin using blenderscad. clearAllObjects() difference(cube((3, 3, 3), center=True), cylinder(r=1, h=100, fn=100, center=True))