Macro 3d Printer Slicer: Difference between revisions
No edit summary |
(Use {{MacroCode}}) |
||
(36 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
{{Macro|Icon=Text-x-python|Name=Export to slicing software for 3D printers|Description=Exports stl file in the same directory as original design file, then opens it in slicing software.|Author=cae2100}} |
|||
<translate> |
|||
<!--T:1--> |
|||
{{Macro |
|||
|Name=Macro_3d_Printer_Slicer |
|||
|Icon=Macro_3d_Printer_Slicer.png |
|||
|Description=Export to slicing software for 3D printers. Exports stl file in the same directory as original design file, then opens it in slicing software.<br/>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 '''[http://kisslicer.com/ KISSlicer]''', but can be modified to use '''[http://slic3r.org/ Slic3r]''', '''[http://wiki.ultimaker.com/Cura Cura]''', or any other 3d printer software. It can also be modified slightly to open up CAM software for CNC machines. |
|||
|Author=cae2100 |
|||
|Version=1.0 |
|||
|Date=2013-10-10 |
|||
|FCVersion=All |
|||
|Download=[https://www.freecadweb.org/wiki/images/9/96/Macro_3d_Printer_Slicer.png ToolBar Icon] |
|||
}} |
|||
==Description== <!--T:2--> |
|||
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. |
|||
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 '''[http://kisslicer.com/ KISSlicer]''', but can be modified to use '''[http://slic3r.org/ Slic3r]''', '''[http://wiki.ultimaker.com/Cura Cura]''', or any other 3d printer software. It can also be modified slightly to open up CAM software for CNC machines. |
|||
<!--T:3--> |
|||
The SLICER varable can be changed to any slicing software of your choosing, just make sure to change it before you try running it or it'll flag an error. |
|||
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. |
|||
<!--T:4--> |
|||
[code] import FreeCAD |
|||
[[File:Macro_3d_Printer_Slicer_00.png|480px]] |
|||
import Mesh |
|||
import sys |
|||
==Script== <!--T:5--> |
|||
import math |
|||
The SLICER variable 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 os |
|||
</translate> |
|||
import subprocess |
|||
# some fuctions |
|||
ToolBar Icon [[Image:Macro_3d_Printer_Slicer.png]] |
|||
def getPlacement(quat,vect,obj): |
|||
if quat[3] > -1 and quat[3] < 1: |
|||
'''Macro_3d_Printer_Slicer.py''' |
|||
delta = math.acos(quat[3])*2.0 |
|||
scale = math.sin(delta/2) |
|||
{{MacroCode|code= |
|||
rx = quat[0]/scale |
|||
import FreeCAD |
|||
ry = quat[1]/scale |
|||
import Mesh |
|||
rz = quat[2]/scale |
|||
import sys |
|||
else: |
|||
import math |
|||
delta = 0 |
|||
import os |
|||
rx = 0 |
|||
import subprocess |
|||
ry = 0 |
|||
# some fuctions |
|||
rz = 1 |
|||
def getPlacement(quat,vect,obj): |
|||
info0 = "translation "+str(vect.x)+" "+str(vect.y)+" "+str(vect.z) |
|||
if quat[3] > -1 and quat[3] < 1: |
|||
info1 = "rotation "+str(rx)+" "+str(ry)+" "+str(rz)+" "+str(delta) |
|||
delta = math.acos(quat[3])*2.0 |
|||
return info0+" "+info1 |
|||
scale = math.sin(delta/2) |
|||
# some definitions |
|||
rx = quat[0]/scale |
|||
placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0,1)) |
|||
ry = quat[1]/scale |
|||
# user need to set this directory where STL files will be placed |
|||
rz = quat[2]/scale |
|||
OutDir = FreeCAD.ActiveDocument.FileName.replace(FreeCAD.ActiveDocument.Label + ".fcstd", "") |
|||
else: |
|||
visible_objs = [] |
|||
delta = 0 |
|||
SLICER = "/kisslicer location/" # Put your Slicer program location here |
|||
rx = 0 |
|||
os.chdir(SLICER) |
|||
ry = 0 |
|||
# Get Objects in document |
|||
rz = 1 |
|||
info0 = "translation "+str(vect.x)+" "+str(vect.y)+" "+str(vect.z) |
|||
objs = doc.Objects |
|||
info1 = "rotation "+str(rx)+" "+str(ry)+" "+str(rz)+" "+str(delta) |
|||
# hide all |
|||
return info0+" "+info1 |
|||
for obj in objs: |
|||
# some definitions |
|||
if obj.ViewObject.isVisible(): |
|||
placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0,1)) |
|||
visible_objs.append(obj) |
|||
# user need to set this directory where slicing software is located |
|||
print "number of volumes "+str(len(visible_objs)) |
|||
OutDir = FreeCAD.ActiveDocument.FileName.replace(FreeCAD.ActiveDocument.Label + ".fcstd", "") |
|||
for obj in visible_objs: |
|||
visible_objs = [] |
|||
# { |
|||
SLICER = "/kisslicer location/" # Put your Slicer program location here |
|||
# get volume |
|||
os.chdir(SLICER) |
|||
volume = obj.Shape.Volume |
|||
# Get Objects in document |
|||
# get Rotation and translation of volume |
|||
doc = App.ActiveDocument |
|||
quat = obj.Placement.Rotation.Q |
|||
objs = doc.Objects |
|||
vect = obj.Placement.Base |
|||
# hide all |
|||
pinfo = getPlacement(quat,vect,obj) |
|||
for obj in objs: |
|||
# reset placement, export it and set at original placement |
|||
if obj.ViewObject.isVisible(): |
|||
oldPlacement = obj.Placement |
|||
visible_objs.append(obj) |
|||
obj.Placement = placement |
|||
for obj in visible_objs: |
|||
obj.Placement = oldPlacement |
|||
# get volume |
|||
stlFile = OutDir+str(doc.Label)+".stl" |
|||
volume = obj.Shape.Volume |
|||
Mesh.export(visible_objs,stlFile) |
|||
# get Rotation and translation of volume |
|||
subprocess.Popen([SLICER + "KISSlicer", stlFile])[/code] |
|||
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]) |
|||
}} |
|||
<translate> |
|||
== Credits == <!--T:6--> |
|||
Thanks to [http://forum.freecadweb.org/viewtopic.php?f=10&t=4686 Wmayer] for his help in writing this script.<br /> |
|||
Original forum topic: http://forum.freecadweb.org/viewtopic.php?f=10&t=4686 |
|||
</translate> |
|||
{{clear}} |
Revision as of 01:08, 8 May 2020
Description |
---|
Export to slicing software for 3D printers. Exports stl file in the same directory as original design file, then opens it in slicing software. 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. Macro version: 1.0 Last modified: 2013-10-10 FreeCAD version: All Download: ToolBar Icon Author: cae2100 |
Author |
cae2100 |
Download |
ToolBar Icon |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
2013-10-10 |
FreeCAD Version(s) |
All |
Default shortcut |
None |
See also |
None |
Description
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.
Script
The SLICER variable 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.
Macro_3d_Printer_Slicer.py
import FreeCAD import Mesh import sys import math import os import subprocess # 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(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
Thanks to Wmayer for his help in writing this script.
Original forum topic: http://forum.freecadweb.org/viewtopic.php?f=10&t=4686