add sub folders for time, removed time on files name, started working on a rec function but not working atm
This commit is contained in:
parent
55e586bcc6
commit
0396dd5f58
|
|
@ -90,9 +90,17 @@ class WindowDialog():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def _createFolder(self, date):
|
def _createFolder(self):
|
||||||
|
date = datetime.today().strftime('%Y-%m-%d')
|
||||||
|
time = datetime.today().strftime('%H:%M:%S')
|
||||||
|
|
||||||
folderPath = f"{FreeCAD.activeDocument().getFileName().rpartition('.')[0]}-{date}-Exports/"
|
folderPath = f"{FreeCAD.activeDocument().getFileName().rpartition('.')[0]}-{date}-Exports/"
|
||||||
|
|
||||||
|
if not os.path.exists(folderPath):
|
||||||
|
os.makedirs(folderPath)
|
||||||
|
|
||||||
|
folderPath += f"{time}/"
|
||||||
|
|
||||||
if not os.path.exists(folderPath):
|
if not os.path.exists(folderPath):
|
||||||
os.makedirs(folderPath)
|
os.makedirs(folderPath)
|
||||||
|
|
||||||
|
|
@ -101,20 +109,20 @@ class WindowDialog():
|
||||||
|
|
||||||
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- #
|
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- #
|
||||||
|
|
||||||
def _exportSketchBasic(self, sketchList, date):
|
def _exportSketchBasic(self, sketchList):
|
||||||
for __O__ in sketchList:
|
for __O__ in sketchList:
|
||||||
__obj__ = []
|
__obj__ = []
|
||||||
__obj__.append(__O__)
|
__obj__.append(__O__)
|
||||||
|
|
||||||
print('Export SVG de : ' + __obj__[0].Label)
|
print('Export SVG de : ' + __obj__[0].Label)
|
||||||
|
|
||||||
fichierSVG = u"" + self.outputRacine + __obj__[0].Label + '-' + date + '.svg'
|
fichierSVG = u"" + self.outputRacine + __obj__[0].Label + '-' + '.svg'
|
||||||
importSVG.export(__obj__, fichierSVG)
|
importSVG.export(__obj__, fichierSVG)
|
||||||
FreeCAD.ActiveDocument.removeObject(__O__.Label)
|
FreeCAD.ActiveDocument.removeObject(__O__.Label)
|
||||||
|
|
||||||
FreeCAD.activeDocument().recompute()
|
FreeCAD.activeDocument().recompute()
|
||||||
|
|
||||||
def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing, date):
|
def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing):
|
||||||
copy_sketchList = sketchList[:]
|
copy_sketchList = sketchList[:]
|
||||||
__obj__ = []
|
__obj__ = []
|
||||||
currentX = 0.0
|
currentX = 0.0
|
||||||
|
|
@ -178,8 +186,8 @@ class WindowDialog():
|
||||||
FreeCAD.activeDocument().recompute()
|
FreeCAD.activeDocument().recompute()
|
||||||
|
|
||||||
if listSize <= 0 or isSVGFull:
|
if listSize <= 0 or isSVGFull:
|
||||||
fichierSVG = u"" + self.outputRacine + 'CALEPINAGE-' + str(SVGNameCounter) + '-' + date + '.svg'
|
fichierSVG = u"" + self.outputRacine + 'CALEPINAGE-' + str(SVGNameCounter) + '-' + '.svg'
|
||||||
print('Export SVG de : ' + u"" + str(os.path.basename(self.outputRacine)) + 'CALEPINAGE-' + str(SVGNameCounter) + '-' + date + '.svg')
|
print('Export SVG de : ' + u"" + str(os.path.basename(self.outputRacine)) + 'CALEPINAGE-' + str(SVGNameCounter) + '-' + '.svg')
|
||||||
importSVG.export(__obj__, fichierSVG)
|
importSVG.export(__obj__, fichierSVG)
|
||||||
for __i__ in __obj__:
|
for __i__ in __obj__:
|
||||||
FreeCAD.ActiveDocument.removeObject(__i__.Label)
|
FreeCAD.ActiveDocument.removeObject(__i__.Label)
|
||||||
|
|
@ -202,7 +210,23 @@ class WindowDialog():
|
||||||
|
|
||||||
# -------- END -------- #
|
# -------- END -------- #
|
||||||
|
|
||||||
def exportSVG(self, isCalepinage, date):
|
def searchDir(self, obj, x = 0.0, y = 0.0, z = 0.0):
|
||||||
|
x1, y1, z1 = x, y, z
|
||||||
|
|
||||||
|
if hasattr(obj, 'Dir'):
|
||||||
|
if obj.Dir.x != 0.0:
|
||||||
|
x1 = obj.Dir.x
|
||||||
|
if obj.Dir.y != 0.0:
|
||||||
|
y1 = obj.Dir.y
|
||||||
|
if obj.Dir.z != 0.0:
|
||||||
|
z1 = obj.Dir.z
|
||||||
|
if hasattr(obj, 'Objects'):
|
||||||
|
for i in obj.Objects:
|
||||||
|
self.searchDir(i, x1, y1, z1)
|
||||||
|
|
||||||
|
return FreeCAD.Vector(x1, y1, z1)
|
||||||
|
|
||||||
|
def exportSVG(self, isCalepinage):
|
||||||
plateLength = self.form.doubleSpinBoxLength.value()
|
plateLength = self.form.doubleSpinBoxLength.value()
|
||||||
plateWidth = self.form.doubleSpinBoxWidth.value()
|
plateWidth = self.form.doubleSpinBoxWidth.value()
|
||||||
spacing = self.form.doubleSpinBoxSpacing.value()
|
spacing = self.form.doubleSpinBoxSpacing.value()
|
||||||
|
|
@ -222,13 +246,8 @@ class WindowDialog():
|
||||||
break
|
break
|
||||||
|
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
if hasattr(obj, 'Dir'):
|
vector = self.searchDir(obj)
|
||||||
sv0 = Draft.make_shape2dview(obj, FreeCAD.Vector(obj.Dir))
|
sv0 = Draft.make_shape2dview(obj, vector)
|
||||||
elif hasattr(obj, 'Objects'):
|
|
||||||
for child in obj.Objects:
|
|
||||||
if hasattr(child, 'Dir'):
|
|
||||||
sv0 = Draft.make_shape2dview(child, FreeCAD.Vector(child.Dir))
|
|
||||||
break
|
|
||||||
|
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
sk = Draft.make_sketch(sv0, autoconstraints=True)
|
sk = Draft.make_sketch(sv0, autoconstraints=True)
|
||||||
|
|
@ -240,15 +259,15 @@ class WindowDialog():
|
||||||
FreeCAD.ActiveDocument.removeObject(sv0.Name)
|
FreeCAD.ActiveDocument.removeObject(sv0.Name)
|
||||||
|
|
||||||
if isCalepinage:
|
if isCalepinage:
|
||||||
self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing, date)
|
self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing)
|
||||||
else:
|
else:
|
||||||
self._exportSketchBasic(sketchList, date)
|
self._exportSketchBasic(sketchList)
|
||||||
|
|
||||||
self._populate_selector_list()
|
self._populate_selector_list()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def exportSTL(self, singleMode, date):
|
def exportSTL(self, singleMode):
|
||||||
objects_to_export = []
|
objects_to_export = []
|
||||||
|
|
||||||
for obj in FreeCADGui.Selection.getSelection():
|
for obj in FreeCADGui.Selection.getSelection():
|
||||||
|
|
@ -271,7 +290,7 @@ class WindowDialog():
|
||||||
|
|
||||||
if not singleMode:
|
if not singleMode:
|
||||||
for obj, label, i in objects_to_export:
|
for obj, label, i in objects_to_export:
|
||||||
filename = os.path.join(self.outputRacine, f"{label}_{i}-{date}.stl")
|
filename = os.path.join(self.outputRacine, f"{label}_{i}.stl")
|
||||||
Mesh.export([obj], filename)
|
Mesh.export([obj], filename)
|
||||||
print(f"Exported STL: {filename}")
|
print(f"Exported STL: {filename}")
|
||||||
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
||||||
|
|
@ -279,7 +298,7 @@ class WindowDialog():
|
||||||
export_objs = [obj for obj, _, _ in objects_to_export]
|
export_objs = [obj for obj, _, _ in objects_to_export]
|
||||||
if export_objs:
|
if export_objs:
|
||||||
label = FreeCAD.activeDocument().Name
|
label = FreeCAD.activeDocument().Name
|
||||||
filename = os.path.join(self.outputRacine, f"{label}-{date}.stl")
|
filename = os.path.join(self.outputRacine, f"{label}.stl")
|
||||||
Mesh.export(export_objs, filename)
|
Mesh.export(export_objs, filename)
|
||||||
print(f"Exported merged STL: {filename}")
|
print(f"Exported merged STL: {filename}")
|
||||||
for obj in export_objs:
|
for obj in export_objs:
|
||||||
|
|
@ -293,13 +312,10 @@ class WindowDialog():
|
||||||
isCalepinage = self.form.checkBoxCalepinage.isChecked()
|
isCalepinage = self.form.checkBoxCalepinage.isChecked()
|
||||||
isCombine = self.form.checkBoxCombine.isChecked()
|
isCombine = self.form.checkBoxCombine.isChecked()
|
||||||
|
|
||||||
dateFolder = datetime.today().strftime('%Y-%m-%d')
|
self.outputRacine = self._createFolder()
|
||||||
dateFiles = datetime.today().strftime('%H:%M:%S')
|
|
||||||
|
|
||||||
self.outputRacine = self._createFolder(dateFolder)
|
self.exportSVG(isCalepinage)
|
||||||
|
self.exportSTL(isCombine)
|
||||||
self.exportSVG(isCalepinage, dateFiles)
|
|
||||||
self.exportSTL(isCombine, dateFiles)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue