Skip to content

Commit

Permalink
MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
limikael committed May 8, 2019
1 parent 4b5badf commit c6c7c85
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
31 changes: 29 additions & 2 deletions Slcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,37 @@ def slice():
DialogUtil.showErrorMessage(e)

def sliceInfo():
pass
try:
doc=SlcrDoc()
doc.exportVisible()
doc.generateGcode()

patterns=[
"; generated by",
"; total filament cost",
"; estimated printing time",
"; filament used"
]

message=""
for line in open(doc.getGcodeFileName()):
for pattern in patterns:
if pattern in line:
message+=line

DialogUtil.showInfoMessage(message)

except Exception as e:
DialogUtil.showErrorMessage(e)

def exportGcode():
pass
try:
doc=SlcrDoc()
doc.exportVisible()
doc.generateGcode()

except Exception as e:
DialogUtil.showErrorMessage(e)

def devReload():
if not os.path.isfile(os.path.dirname(__file__)+"/__dev__.py"):
Expand Down
6 changes: 6 additions & 0 deletions SlcrDialogUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ def showErrorMessage(err):
message=str(err)
dialog=QtGui.QMessageBox(QtGui.QMessageBox.Critical,'Error',message)
dialog.setWindowModality(QtCore.Qt.ApplicationModal)
dialog.exec_()

def showInfoMessage(err):
message=str(err)
dialog=QtGui.QMessageBox(QtGui.QMessageBox.Information,'Info',message)
dialog.setWindowModality(QtCore.Qt.ApplicationModal)
dialog.exec_()
32 changes: 29 additions & 3 deletions SlcrDoc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import FreeCAD
import os
import Mesh
import FreeCAD, os, Mesh, subprocess

class SlcrDoc:
def __init__(self):
Expand Down Expand Up @@ -46,3 +44,31 @@ def getStlFileName(self):
raise Exception("Please save the document first to give it a filename.")

return os.path.splitext(self.doc.FileName)[0]+".stl"

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

return os.path.splitext(self.doc.FileName)[0]+".gcode"

def generateGcode(self):
preferences=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/slcr")
slic3rPath=preferences.GetString('slic3rPath')
if not slic3rPath.strip():
raise Exception("Please set the path to the slic3r executable in preferences")

slic3rIniPath=preferences.GetString('slic3rIniPath')
if not slic3rIniPath.strip():
raise Exception("Please set the path to the slic3r profile .ini in preferences")

slic3rOpts=[
slic3rPath,
"--no-gui",
"--load",
slic3rIniPath,
self.getStlFileName(),
"--output",
self.getGcodeFileName()
]

subprocess.check_output(slic3rOpts)

0 comments on commit c6c7c85

Please sign in to comment.