diff --git a/Conversion/3dPrinterSlicerIndividualParts.FCMacro b/Conversion/3dPrinterSlicerIndividualParts.FCMacro new file mode 100644 index 0000000..14a11da --- /dev/null +++ b/Conversion/3dPrinterSlicerIndividualParts.FCMacro @@ -0,0 +1,75 @@ +# This code, when run, will export the visible bodies at the top level (bodies deeper in the tree will be ignored) +# of the currently open design to individual STL files, and open them it in the slicing software that you use. +# This macro will look for Cura as the default but you can change it to any other slider by changing the +# SLICERAPP variable in the source code. + +# It is best used by creating a link to the macro on the toolbar, and when your ready to slice the object, +# just click it and your objects, as they appear on the screen in FreeCAD will appear on your slicing software's +# interface, ready to slice. It will also create several STL files with the same filename as the design file and +# the part label in the same directory as the design file. + +__Name__ = '3d Printer Slicer Individual Parts' +__Comment__ = 'Exports each visible body indiviually and sends the parts to the slicer' +__Author__ = 'wayofwood,cae2100' +__Version__ = '1.0' +__Date__ = '2020-11-10' +__License__ = 'LGPL-2.0-or-later' +__Web__ = 'https://wiki.freecadweb.org/Macro_3d_Printer_Slicer_Individual_Parts' +__Wiki__ = 'https://wiki.freecadweb.org/Macro_3d_Printer_Slicer_Individual_Parts' +__Icon__ = '3d_Printer_Slicer.FCMacro.svg' +__Help__ = 'If you want to use a different slicer than cura please change the SLICERAPP variable in the source code' +__Status__ = 'Alpha' +__Requires__ = 'no limitations known' +__Communication__ = 'https://forum.freecadweb.org/viewtopic.php?f=22&t=51867&p=445679#p445679' +__Files__ = '3d_Printer_Slicer.FCMacro.svg' + + +import FreeCAD +import Mesh +import sys +import math +import os +import subprocess + +SLICERAPP= "cura" # Put your Slicer program here + +# some fuctions +def getPlacement(quat,vect,obj): + if quat[3] > -1 and quat[3] < 1: + delta = math.acos(quat[3])*2.0 + scale = math.sin(delta/2) + rx = quat[0]/scale + ry = quat[1]/scale + rz = quat[2]/scale + else: + delta = 0 + rx = 0 + ry = 0 + rz = 1 + info0 = "translation "+str(vect.x)+" "+str(vect.y)+" "+str(vect.z) + info1 = "rotation "+str(rx)+" "+str(ry)+" "+str(rz)+" "+str(delta) + return info0+" "+info1 +# some definitions +placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0,1)) +# user need to set this directory where slicing software is located +OutDir = FreeCAD.ActiveDocument.FileName.replace(".FCStd", "--") +visible_objs = [] +# Get Objects in document +doc = App.ActiveDocument +objs = doc.Objects +stlFile = "" +stlFiles = [ SLICERAPP ] +# hide all +for obj in objs: + #print(obj.Label + "//" + obj.TypeId) + #print(len(obj.InList)) + if obj.ViewObject.isVisible() and hasattr(obj, 'Shape') and (len(obj.InList) <= 1): + visible_objs.append(obj) +for obj in visible_objs: + stlFile = OutDir+str(obj.Label)+".stl" + Mesh.export([obj],stlFile) + stlFiles.append(stlFile) + print ("Exporting " + stlFile + "\n") +print ("Calling subprocess: " + str(stlFiles)+"\n") +subprocess.Popen(stlFiles) + diff --git a/Conversion/3dPrinterSlicerIndividualParts.svg b/Conversion/3dPrinterSlicerIndividualParts.svg new file mode 100644 index 0000000..aa38990 --- /dev/null +++ b/Conversion/3dPrinterSlicerIndividualParts.svg @@ -0,0 +1,118 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + +