Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new macro to send individual parts to the slicer #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Conversion/3dPrinterSlicerIndividualParts.FCMacro
Original file line number Diff line number Diff line change
@@ -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)

118 changes: 118 additions & 0 deletions Conversion/3dPrinterSlicerIndividualParts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.