├── 10K.blend ├── 20181012 - gcode_exporter - test file 01.blend ├── 20181013 - gcode_exporter - spiral.blend ├── 20181023 - gcode_exporter - test file 02.blend ├── README.md ├── SV_Displace_Distortion.blend ├── curves_to_gcode_G1.py ├── export_gcode_G1.py ├── multiple_curves_array_v0.2.py ├── realtime_mesh_exporter-b280.py ├── realtime_mesh_exporter.py └── z-slicer.py /10K.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alessandro-zomparelli/blender-scripts/754baa4b9eb2e8beb4779cd00c24ed3b953e308f/10K.blend -------------------------------------------------------------------------------- /20181012 - gcode_exporter - test file 01.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alessandro-zomparelli/blender-scripts/754baa4b9eb2e8beb4779cd00c24ed3b953e308f/20181012 - gcode_exporter - test file 01.blend -------------------------------------------------------------------------------- /20181013 - gcode_exporter - spiral.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alessandro-zomparelli/blender-scripts/754baa4b9eb2e8beb4779cd00c24ed3b953e308f/20181013 - gcode_exporter - spiral.blend -------------------------------------------------------------------------------- /20181023 - gcode_exporter - test file 02.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alessandro-zomparelli/blender-scripts/754baa4b9eb2e8beb4779cd00c24ed3b953e308f/20181023 - gcode_exporter - test file 02.blend -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blender-scripts 2 | -------------------------------------------------------------------------------- /SV_Displace_Distortion.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alessandro-zomparelli/blender-scripts/754baa4b9eb2e8beb4779cd00c24ed3b953e308f/SV_Displace_Distortion.blend -------------------------------------------------------------------------------- /curves_to_gcode_G1.py: -------------------------------------------------------------------------------- 1 | #------------------- export gcode G1 movements -----------------# 2 | # # 3 | # Simple script for exporting selected curves as G1 lines for # 4 | # generating a gcode from curves. XYZ coordinates are correctly # 5 | # generated accordingly to model size and position. # 6 | # E for extruding filament need to be fixed. # 7 | # # 8 | # Alessandro Zomparelli # 9 | # (2016) # 10 | # # 11 | # # 12 | # Creative Commons # 13 | # CC BY-SA 3.0 # 14 | # http://creativecommons.org/licenses/by-sa/3.0/ # 15 | 16 | 17 | # SETTINGS 18 | 19 | extrusion_parameter = 10 # adjust the amount of extruded filament 20 | 21 | 22 | 23 | import bpy 24 | 25 | obj = bpy.context.active_object 26 | rec_path = bpy.path.abspath("//" + obj.name) 27 | 28 | 29 | def simple_curves_export(): 30 | 31 | crvs = obj.data.splines 32 | 33 | # sort curves in Z 34 | sorted_curves = {} 35 | for i in range(len(crvs)): 36 | sorted_curves[crvs[i].points[0].co[2]] = i 37 | 38 | print(sorted_curves) 39 | 40 | pts_list = [] 41 | for id in sorted_curves: 42 | for pt in crvs[sorted_curves[id]].points: 43 | pts_list.append(pt.co) 44 | 45 | lines = [] 46 | obj_text = open(rec_path + '.gcode', 'w') 47 | 48 | #lines.append(str(len(pts_list)) + '\n') 49 | for i in range(0, len(pts_list)): 50 | pt1 = pts_list[i] 51 | if i>0: 52 | distVec = pt0 - pt1 53 | extrusion = distVec.length*extrusion_parameter 54 | else: extrusion = 0 55 | 56 | # open mesh 57 | co_1 = str(pts_list[i][0]) 58 | co_2 = str(pts_list[i][1]) 59 | co_3 = str(pts_list[i][2]) 60 | extrusion_string = "%.1f" % extrusion 61 | co = 'G1 ' + 'X' + co_1 + ' Y' + co_2 + ' Z' + co_3 + ' E' + extrusion_string + '\n' 62 | lines.append(co) 63 | 64 | pt0 = pt1 65 | 66 | obj_text.writelines(lines) 67 | obj_text.close() 68 | 69 | ''' 70 | obj_text = open(rec_path + '.curves', 'w') 71 | #obj_text.write(str(len(crvs)) + '\n') 72 | for crv in crvs: 73 | obj_text.write(str(len(crv.points))) 74 | obj_text.write('\n') 75 | obj_text.close() 76 | ''' 77 | 78 | if(obj.type == 'CURVE'): simple_curves_export() -------------------------------------------------------------------------------- /export_gcode_G1.py: -------------------------------------------------------------------------------- 1 | #------------------- export gcode G1 movements -----------------# 2 | # # 3 | # Simple script for exporting selected curves as G1 lines for # 4 | # generating a gcode from curves. XYZ coordinates are correctly # 5 | # generated accordingly to model size and position. # 6 | # E for extruding filament need to be fixed. # 7 | # # 8 | # W A R N I N G ! ! ! # 9 | # # 10 | # The code is still a work in progress. Use it only if you are # 11 | # expert in the generation of gcode files, because wrong values # 12 | # can damage the 3D-printer. # 13 | # # 14 | # Alessandro Zomparelli # 15 | # (2016) # 16 | # # 17 | # # 18 | # Creative Commons # 19 | # CC BY-SA 3.0 # 20 | # http://creativecommons.org/licenses/by-sa/3.0/ # 21 | 22 | 23 | # SETTINGS 24 | 25 | extrusion_parameter = 10 # adjust the amount of extruded filament 26 | 27 | 28 | 29 | import bpy 30 | 31 | obj = bpy.context.active_object 32 | rec_path = bpy.path.abspath("//" + obj.name) 33 | 34 | 35 | def simple_curves_export(): 36 | 37 | crvs = obj.data.splines 38 | 39 | # sort curves in Z 40 | sorted_curves = {} 41 | for i in range(len(crvs)): 42 | sorted_curves[crvs[i].points[0].co[2]] = i 43 | 44 | print(sorted_curves) 45 | 46 | pts_list = [] 47 | for id in sorted_curves: 48 | for pt in crvs[sorted_curves[id]].points: 49 | pts_list.append(pt.co) 50 | 51 | lines = [] 52 | obj_text = open(rec_path + '.gcode', 'w') 53 | 54 | #lines.append(str(len(pts_list)) + '\n') 55 | for i in range(0, len(pts_list)): 56 | pt1 = pts_list[i] 57 | if i>0: 58 | distVec = pt0 - pt1 59 | extrusion = distVec.length*extrusion_parameter 60 | else: extrusion = 0 61 | 62 | # open mesh 63 | co_1 = str(pts_list[i][0]) 64 | co_2 = str(pts_list[i][1]) 65 | co_3 = str(pts_list[i][2]) 66 | extrusion_string = "%.1f" % extrusion 67 | co = 'G1 ' + 'X' + co_1 + ' Y' + co_2 + ' Z' + co_3 + ' E' + extrusion_string + '\n' 68 | lines.append(co) 69 | 70 | pt0 = pt1 71 | 72 | obj_text.writelines(lines) 73 | obj_text.close() 74 | 75 | ''' 76 | obj_text = open(rec_path + '.curves', 'w') 77 | #obj_text.write(str(len(crvs)) + '\n') 78 | for crv in crvs: 79 | obj_text.write(str(len(crv.points))) 80 | obj_text.write('\n') 81 | obj_text.close() 82 | ''' 83 | 84 | if(obj.type == 'CURVE'): simple_curves_export() -------------------------------------------------------------------------------- /multiple_curves_array_v0.2.py: -------------------------------------------------------------------------------- 1 | #--------------------- MULTIPLE CURVES ARRAY -------------------# 2 | #------------------------------ v0.2 ---------------------------# 3 | # # 4 | # The aim of this script is to allow the creation of arrays # 5 | # along multiple curves. By default, using an array modifier # 6 | # that fits a curve, and then a curve modifier along the same # 7 | # curve makes the object following only a single curve. # 8 | # Also if your curve object has multiple splines, it will # 9 | # follow just one of them. With this script you can select your # 10 | # object and make it working along all the splines of the curve # 11 | # object. # 12 | # # 13 | # The option "merge" will allow to automatically merge the # 14 | # resulting object. This will apply all the modifiers. # 15 | # If "merge" is False, then all the generated object will be # 16 | # linked copies. # 17 | # # 18 | # Alessandro Zomparelli # 19 | # (2018) # 20 | # # 21 | # http://www.alessandrozomparelli.com/ # 22 | # # 23 | # Creative Commons # 24 | # CC BY-SA 3.0 # 25 | # http://creativecommons.org/licenses/by-sa/3.0/ # 26 | 27 | import bpy 28 | 29 | merge = False 30 | 31 | scn = bpy.context.scene 32 | ob = bpy.context.object 33 | try: 34 | for m in ob.modifiers: 35 | if m.type == 'ARRAY': 36 | curve = m.curve 37 | except: 38 | pass 39 | 40 | curves = [] 41 | objects = [] 42 | bpy.ops.object.select_all(action='DESELECT') 43 | bpy.context.scene.objects.active = curve 44 | curve.select = True 45 | bpy.ops.object.mode_set(mode = 'EDIT') 46 | 47 | print("split curves") 48 | 49 | n_splines = len(curve.data.splines) 50 | next = curve 51 | for i in range(n_splines): 52 | new_crv = next.copy() 53 | new_crv.data = next.data.copy() 54 | if i > 0: new_crv.data.splines.remove(new_crv.data.splines[0]) 55 | next = new_crv.copy() 56 | next.data = new_crv.data.copy() 57 | curves.append(new_crv) 58 | delete = False 59 | for s in new_crv.data.splines: 60 | if delete: new_crv.data.splines.remove(s) 61 | delete = True 62 | scn.objects.link(new_crv) 63 | 64 | bpy.ops.object.mode_set(mode = 'OBJECT') 65 | 66 | bpy.ops.object.select_all(action='DESELECT') 67 | 68 | print("copy objects") 69 | 70 | for c in curves: 71 | new_ob = ob.copy() 72 | if merge: 73 | new_ob.data = ob.data.copy() 74 | objects.append(new_ob) 75 | scn.objects.link(new_ob) 76 | for m in new_ob.modifiers: 77 | if m.type == 'CURVE': m.object = c 78 | if m.type == 'ARRAY': m.curve = c 79 | 80 | bpy.context.scene.update() 81 | 82 | if merge: 83 | print("merge objects") 84 | for o in objects: 85 | o.data = o.to_mesh(scn, apply_modifiers=True, settings = 'PREVIEW') 86 | o.modifiers.clear() 87 | o.select = True 88 | scn.objects.active = o 89 | bpy.ops.object.join() 90 | for c in curves: bpy.data.objects.remove(c) 91 | -------------------------------------------------------------------------------- /realtime_mesh_exporter-b280.py: -------------------------------------------------------------------------------- 1 | #-------------------- REALTIME MESH EXPORTER -------------------# 2 | #-------------------------(basic version)-----------------------# 3 | # # 4 | # Realtime Mesh Exporter is a script that allows you to save # 5 | # the mesh in real time for immediate reading from external # 6 | # applications. You can set exporting options for different # 7 | # objects in "Object Data" menu. # 8 | # # 9 | # Alessandro Zomparelli # 10 | # (2013) # 11 | # # 12 | # http://sketchesofcode.wordpress.com/ # 13 | # # 14 | # Creative Commons # 15 | # CC BY-SA 3.0 # 16 | # http://creativecommons.org/licenses/by-sa/3.0/ # 17 | 18 | bl_info = { 19 | "name": "Realtime Mesh Exporter", 20 | "author": "Alessandro Zomparelli (Co-de-iT)", 21 | "version": (0, 0, 1), 22 | "blender": (2, 80, 0), 23 | "location": "", 24 | "description": "Save mesh data to external files", 25 | "warning": "", 26 | "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/" 27 | "Py/Scripts/Mesh/Tissue", 28 | "tracker_url": "https://plus.google.com/u/0/+AlessandroZomparelli/", 29 | "category": "Mesh"} 30 | 31 | import bpy 32 | 33 | class OBJECT_PT_realtime_export(bpy.types.Panel): 34 | bl_idname = "OBJECT_PT_realtime_export" 35 | bl_label = "Real-time Mesh Exporter" 36 | bl_space_type = 'PROPERTIES' 37 | bl_region_type = 'WINDOW' 38 | bl_context = "data" 39 | 40 | @classmethod 41 | def poll(cls, context): 42 | try: 43 | ob = context.object 44 | return ob.type == 'MESH' 45 | except: return False 46 | 47 | def draw(self, context): 48 | layout = self.layout 49 | obj = context.object 50 | 51 | row = layout.row() 52 | row.prop(obj, 'prop_record') 53 | row.operator('object.export_mesh_data', icon='EXPORT') 54 | row = layout.row() 55 | row.prop(obj, 'RT_apply_modifiers') 56 | row.prop(obj, 'RT_export_weight') 57 | layout.label(text="File Path:") 58 | layout.prop(obj, 'RT_prop_path', icon='FILE_FOLDER') 59 | 60 | if obj.prop_record: simple_export(obj, obj.RT_prop_path) 61 | 62 | 63 | def simple_export(obj, rec_path): 64 | 65 | if obj.RT_apply_modifiers: mesh = obj.to_mesh(bpy.context.depsgraph, True) 66 | else: mesh = obj.data 67 | 68 | # save VERTICES 69 | v_list = [] 70 | for v in mesh.vertices: 71 | v_list.append(v.co) 72 | 73 | lines = [] 74 | rec_path = bpy.path.abspath(rec_path) 75 | obj_text = open(rec_path + '_vertices.txt', 'w+') 76 | 77 | lines.append(str(len(v_list)) + '\n') 78 | for i in range(0, len(v_list)): 79 | #open mesh 80 | co_1 = str(v_list[i][0]) 81 | co_2 = str(v_list[i][1]) 82 | co_3 = str(v_list[i][2]) 83 | co = co_1 + ', ' + co_2 + ', ' + co_3 + '\n' 84 | lines.append(co) 85 | 86 | obj_text.writelines(lines) 87 | obj_text.close() 88 | 89 | # save FACES 90 | obj_text = open(rec_path + '_faces.txt', 'w+') 91 | obj_text.write(str(len(mesh.polygons)) + '\n') 92 | for f in mesh.polygons: 93 | for i in range(0,len(f.vertices)): 94 | a=str(f.vertices[i]) 95 | if i != len(f.vertices) - 1: 96 | a += ' ' 97 | obj_text.write(a) 98 | obj_text.write('\n') 99 | obj_text.close() 100 | 101 | # save WEIGHT 102 | if obj.RT_export_weight and obj.vertex_groups.active: 103 | obj_text = open(rec_path + '_weight.txt', 'w+') 104 | obj_text.write(str(len(mesh.vertices)) + '\n') 105 | group_id = obj.vertex_groups.active_index 106 | for v in mesh.vertices: 107 | weight = 0 108 | for w in v.groups: 109 | if w.group == group_id: 110 | weight = w.weight 111 | obj_text.write(str(weight) + '\n') 112 | obj_text.close() 113 | 114 | 115 | class export_mesh_data(bpy.types.Operator): 116 | bl_idname = "object.export_mesh_data" 117 | bl_label = "Export Mesh Data" 118 | bl_description = ("") 119 | bl_options = {'REGISTER', 'UNDO'} 120 | 121 | def execute(self, context): 122 | obj = bpy.context.object 123 | simple_export(obj, obj.RT_prop_path) 124 | return {'FINISHED'} 125 | 126 | classes = ( 127 | OBJECT_PT_realtime_export, 128 | export_mesh_data 129 | ) 130 | 131 | def register(): 132 | from bpy.utils import register_class 133 | for cls in classes: 134 | bpy.utils.register_class(cls) 135 | bpy.types.Object.prop_record = bpy.props.BoolProperty(name = "Active Real-time", description = "Active realtime recording", default = False) 136 | bpy.types.Object.RT_apply_modifiers = bpy.props.BoolProperty(name = "Modifiers", description = "Apply Modifiers", default = False) 137 | bpy.types.Object.RT_export_weight = bpy.props.BoolProperty(name = "Export Weight", description = "Export Active Weight", default = False) 138 | bpy.types.Object.RT_prop_path = bpy.props.StringProperty(name="", description="Recording Folder", subtype='FILE_PATH') 139 | 140 | def unregister(): 141 | from bpy.utils import unregister_class 142 | for cls in classes: 143 | bpy.utils.unregister_class(cls) 144 | -------------------------------------------------------------------------------- /realtime_mesh_exporter.py: -------------------------------------------------------------------------------- 1 | #-------------------- REALTIME MESH EXPORTER -------------------# 2 | #-------------------------(basic version)-----------------------# 3 | # # 4 | # Realtime Mesh Exporter is a script that allows you to save # 5 | # the mesh in real time for immediate reading from external # 6 | # applications. You can set exporting options for different # 7 | # objects in "Object Data" menu. # 8 | # # 9 | # Alessandro Zomparelli # 10 | # (2013) # 11 | # # 12 | # http://sketchesofcode.wordpress.com/ # 13 | # # 14 | # Creative Commons # 15 | # CC BY-SA 3.0 # 16 | # http://creativecommons.org/licenses/by-sa/3.0/ # 17 | 18 | import bpy 19 | 20 | class ObjectButtonsPanel(bpy.types.Panel): 21 | bl_idname = "OBJECT_PT_realtime_export" 22 | bl_label = "Select" 23 | bl_space_type = 'PROPERTIES' 24 | bl_region_type = 'WINDOW' 25 | bl_context = "data" 26 | 27 | class OBJECT_PT_realtime_export(ObjectButtonsPanel): 28 | bl_label = "Real-time Mesh Exporter" 29 | 30 | 31 | def draw(self, context): 32 | layout = self.layout 33 | obj = context.object 34 | 35 | row = layout.row() 36 | row.prop(obj, 'prop_record') 37 | row.prop(obj, 'apply_modifiers') 38 | layout.label("File Path:") 39 | layout.prop(obj, 'prop_path', icon='FILE_FOLDER') 40 | 41 | if obj.prop_record: simple_export(obj, obj.prop_path) 42 | 43 | 44 | def simple_export(obj, rec_path): 45 | 46 | if obj.apply_modifiers: mesh = obj.to_mesh(bpy.context.scene, apply_modifiers=True, settings = 'RENDER') 47 | else: mesh = obj.data 48 | 49 | v_list = [] 50 | for v in mesh.vertices: 51 | v_list.append(v.co) 52 | 53 | lines = [] 54 | obj_text = open(rec_path + '.vertices', 'w') 55 | 56 | lines.append(str(len(v_list)) + '\n') 57 | for i in range(0, len(v_list)): 58 | #open mesh 59 | co_1 = str(v_list[i][0]) 60 | co_2 = str(v_list[i][1]) 61 | co_3 = str(v_list[i][2]) 62 | co = co_1 + ' ' + co_2 + ' ' + co_3 + '\n' 63 | lines.append(co) 64 | 65 | obj_text.writelines(lines) 66 | obj_text.close() 67 | 68 | obj_text = open(rec_path + '.faces', 'w') 69 | obj_text.write(str(len(mesh.polygons)) + '\n') 70 | for f in mesh.polygons: 71 | for i in range(0,len(f.vertices)): 72 | a=str(f.vertices[i]) 73 | if i != len(f.vertices) - 1: 74 | a += ' ' 75 | obj_text.write(a) 76 | obj_text.write('\n') 77 | obj_text.close() 78 | 79 | def initialize(): 80 | bpy.types.Object.prop_record = bpy.props.BoolProperty(name = "Active Real-time", description = "Active realtime recording", default = False) 81 | bpy.types.Object.apply_modifiers = bpy.props.BoolProperty(name = "Modifiers", description = "Apply Modifiers", default = False) 82 | bpy.types.Object.prop_path = bpy.props.StringProperty(name="", description="Recording Folder", subtype='FILE_PATH') 83 | 84 | initialize() 85 | bpy.utils.register_class(OBJECT_PT_realtime_export) 86 | -------------------------------------------------------------------------------- /z-slicer.py: -------------------------------------------------------------------------------- 1 | #--------------------------- z slicer --------------------------# 2 | # # 3 | # Simple script for mesh slicing through planes moving along # 4 | # the z-axis. # 5 | # # 6 | # Alessandro Zomparelli # 7 | # (2016) # 8 | # # 9 | # # 10 | # Creative Commons # 11 | # CC BY-SA 3.0 # 12 | # http://creativecommons.org/licenses/by-sa/3.0/ # 13 | 14 | # SETTINGS 15 | 16 | apply_modifiers = True # set True if you want to consider the Modified object 17 | join_slices= False # set True if you want to join together all generated slices 18 | convert_to_curve = True # set True if you want to convert the final result to curves 19 | z_step = 0.05 # set the distance between each slice 20 | 21 | 22 | import bpy 23 | 24 | ob = bpy.context.active_object 25 | bpy.ops.object.select_all(action='TOGGLE') 26 | 27 | # create clone 28 | me = ob.to_mesh(scene=bpy.context.scene, apply_modifiers=apply_modifiers, settings='PREVIEW') 29 | me.transform(ob.matrix_world) 30 | ob1 = bpy.data.objects.new('clone', me) 31 | bpy.context.scene.objects.link(ob1) 32 | z_min = ob1.bound_box[0][2] 33 | z_max = ob1.bound_box[1][2] 34 | 35 | # delete clone 36 | ob1.select = True 37 | bpy.context.scene.objects.active = ob1 38 | bpy.ops.object.delete() 39 | 40 | i = 0 41 | while True: 42 | ob_new = bpy.data.objects.new(str(i), me.copy()) 43 | bpy.context.scene.objects.link(ob_new) 44 | #ob_new.scale = ob.scale 45 | #ob_new.location = ob.location 46 | #bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) 47 | #if(i == 0): 48 | # z_min = ob_new.bound_box[0][2] 49 | # z_max = ob_new.bound_box[1][2] 50 | ob_new.select = True 51 | bpy.context.scene.objects.active = ob_new 52 | bpy.ops.object.mode_set(mode = 'EDIT') 53 | bpy.ops.mesh.select_all(action = 'SELECT') 54 | bpy.ops.mesh.bisect(plane_co=(0, 0, z_min + z_step*i), plane_no=(0, 0, 1), use_fill=False, clear_inner=True, clear_outer=True, threshold=0.0001, xstart=0, xend=0, ystart=0, yend=0) 55 | bpy.ops.object.mode_set(mode = 'OBJECT') 56 | i+=1 57 | if(z_min + i*z_step > z_max): 58 | break 59 | 60 | if(join_slices): 61 | bpy.ops.object.join() 62 | if(convert_to_curve): 63 | bpy.ops.object.convert(target='CURVE') 64 | 65 | 66 | --------------------------------------------------------------------------------