Skip to content

Commit

Permalink
stl export command
Browse files Browse the repository at this point in the history
  • Loading branch information
limikael committed May 8, 2019
1 parent a64fc8d commit b744c23
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
__pycache__
__dev__.py
29 changes: 29 additions & 0 deletions Slcr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os, importlib, sys
from SlcrDoc import SlcrDoc
from SlcrDialogUtil import DialogUtil

def exportVisible():
try:
doc=SlcrDoc()
doc.exportVisible()

except Exception as e:
DialogUtil.showErrorMessage(e)

def slice():
pass

def sliceInfo():
pass

def exportGcode():
pass

def devReload():
if not os.path.isfile(os.path.dirname(__file__)+"/__dev__.py"):
return

print("Reloading module")
importlib.reload(sys.modules["SlcrDialogUtil"])
importlib.reload(sys.modules["SlcrDoc"])
importlib.reload(sys.modules["Slcr"])
8 changes: 8 additions & 0 deletions SlcrDialogUtil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from PySide import QtCore, QtGui

class DialogUtil:
def showErrorMessage(err):
message=str(err)
dialog=QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Error',message)
dialog.setWindowModality(QtCore.Qt.ApplicationModal)
dialog.exec_()
43 changes: 43 additions & 0 deletions SlcrDoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import FreeCAD
import os
import Mesh

class SlcrDoc:
def __init__(self):
self.doc=FreeCAD.ActiveDocument
if not self.doc:
raise Exception("No document open to slice")

def hasInvisibleParent(self, o):
for parent in o.InList:
if parent.TypeId=="App::Part" or parent.TypeId=="PartDesign::Body":
if not parent.ViewObject.isVisible():
return True

if self.hasInvisibleParent(parent):
return True

return False

def getVisibleObjects(self):
visibleObjs=[]
for obj in self.doc.Objects:
if obj.TypeId!="App::Part" and obj.TypeId!="PartDesign::Body":
if obj.ViewObject.isVisible() and not self.hasInvisibleParent(obj):
visibleObjs.append(obj)

return visibleObjs

def exportVisible(self):
if self.doc.FileName=="":
raise Exception("Please save the document first to give it a filename.")

visibleObjs=self.getVisibleObjects()
if not len(visibleObjs):
raise Exception("No visible objects to export")

# for obj in visibleObjs:
# print(obj.Name)

stlFileName=os.path.splitext(self.doc.FileName)[0]+".stl"
Mesh.export(visibleObjs,stlFileName)
14 changes: 9 additions & 5 deletions SlcrGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# (c) 2001 Juergen Riegel
# License LGPL

import FreeCAD, FreeCADGui, os
import FreeCAD, FreeCADGui, os, Slcr

class CmdExportVisible:
def Activated(self):
FreeCAD.Console.PrintMessage("Hello, World!\n")
Slcr.devReload()
Slcr.exportVisible()
def IsActive(self):
return True
def GetResources(self):
Expand All @@ -22,7 +23,8 @@ def GetResources(self):

class CmdSlice:
def Activated(self):
FreeCAD.Console.PrintMessage("Hello, World!\n")
Slcr.devReload()
Slcr.slice()
def IsActive(self):
return True
def GetResources(self):
Expand All @@ -35,7 +37,8 @@ def GetResources(self):

class CmdSliceInfo:
def Activated(self):
FreeCAD.Console.PrintMessage("Hello, World!\n")
Slcr.devReload()
Slcr.sliceInfo()
def IsActive(self):
return True
def GetResources(self):
Expand All @@ -48,7 +51,8 @@ def GetResources(self):

class CmdExportGcode:
def Activated(self):
FreeCAD.Console.PrintMessage("Hello, World!\n")
Slcr.devReload()
Slcr.exportGcode()
def IsActive(self):
return True
def GetResources(self):
Expand Down

0 comments on commit b744c23

Please sign in to comment.