Difference between revisions of "Macro 3d Printer Slicer"
Revision as of 20:18, 9 October 2013
This code, when run, will export the currently open design to STL file, and open it in the slicing software that you use. This example is for KISSlicer, but can be modified to use Slic3r, cura, or any other 3d printer software. It can also be modified slightly to open up CAM software for CNC machines.
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 object, as it appears on the screen in FreeCAD will appear on your slicing software's interface, ready to slice. It will also create an STL file with the same filename as the design file in the same directory as the design file as a backup.
The SLICER varable can be changed to any slicing software of your choosing, just make sure to set it before you try running it or it'll flag an error with the script.
import FreeCAD import Mesh import sys import math import os import subprocess #(FreeCAD.ActiveDocument.Label + ".fcstd", "") visible_objs = [] SLICER = "/kisslicer location/" # Put your Slicer program location here os.chdir(SLICER) # Get Objects in document doc = App.ActiveDocument objs = doc.Objects # hide all for obj in objs: if obj.ViewObject.isVisible(): visible_objs.append(obj) for obj in visible_objs: # { # get volume volume = obj.Shape.Volume # get Rotation and translation of volume quat = obj.Placement.Rotation.Q vect = obj.Placement.Base pinfo = getPlacement(quat,vect,obj) # reset placement, export it and set at original placement oldPlacement = obj.Placement obj.Placement = placement obj.Placement = oldPlacement stlFile = OutDir+str(doc.Label)+".stl" Mesh.export(visible_objs,stlFile) subprocess.Popen([SLICER + "KISSlicer", stlFile])
Credits
Thank you Wmayer for his help in writing this script.