-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__pycache__ | ||
__pycache__ | ||
__dev__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters