From 8dfec0d603788ddeab7ceefa0cb6d783e4c941d8 Mon Sep 17 00:00:00 2001 From: Thomas-Alexandre Moreau Date: Tue, 8 Apr 2025 14:50:37 +0200 Subject: [PATCH] ui update --- MultiExport.FCMacro | 70 ++++++++++++++++++++++++++------------ MultiExport/MultiExport.ui | 12 +++++-- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/MultiExport.FCMacro b/MultiExport.FCMacro index 02d7c88..88ef9e6 100755 --- a/MultiExport.FCMacro +++ b/MultiExport.FCMacro @@ -9,9 +9,11 @@ import Mesh class WindowDialog(): def __init__(self): + self.outputRacine = self._createFolder() self.ui_file = os.path.join(FreeCAD.getUserMacroDir(True), 'MultiExport/MultiExport.ui') self.form = FreeCADGui.PySideUic.loadUi(self.ui_file) self._connect_widgets() + self._populate_selector_list() self.form.show() def _connect_widgets(self): @@ -19,11 +21,37 @@ class WindowDialog(): self.form.pushButtonCalepinage.pressed.connect(lambda: self.exportSVG(True)) self.form.pushButtonSTLSingle.pressed.connect(lambda: self.exportSTL(True)) self.form.pushButtonSTLMulti.pressed.connect(lambda: self.exportSTL(False)) + self.form.listWidgetSelector.itemSelectionChanged.connect(self._on_selector_item_changed) + + + def _populate_selector_list(self): + self.form.listWidgetSelector.clear() # Clear the list first + for obj in FreeCAD.ActiveDocument.Objects: + if obj.Label.startswith("EXP-"): + self.form.listWidgetSelector.addItem(obj.Label) + + def _on_selector_item_changed(self): + selected_items = self.form.listWidgetSelector.selectedItems() + selected_labels = [item.text() for item in selected_items] + + FreeCADGui.Selection.clearSelection() # Clear previous selection + + # Select objects in FreeCAD based on labels selected in the list + for obj in FreeCAD.ActiveDocument.Objects: + if obj.Label in selected_labels: + FreeCADGui.Selection.addSelection(obj) + + def _createFolder(self): + folderPath = f"{FreeCAD.activeDocument().getFileName().rpartition('.')[0]}-Exports/" + + if not os.path.exists(folderPath): + os.makedirs(folderPath) + + return folderPath # -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- # def _exportSketchBasic(self, sketchList): - outputRacine = App.activeDocument().getFileName().rpartition('.')[0] for __O__ in sketchList: __obj__ = [] __obj__.append(__O__) @@ -31,16 +59,15 @@ class WindowDialog(): print('Export SVG de : ' + __obj__[0].Label) oldPlace = __obj__[0].Placement - __obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0)) - fichierSVG = u"" + outputRacine + '--' + __obj__[0].Label + '.svg' + __obj__[0].Placement=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(FreeCAD.Vector(1,0,0),0), FreeCAD.Vector(0,0,0)) + fichierSVG = u"" + self.outputRacine + '--' + __obj__[0].Label + '.svg' importSVG.export(__obj__, fichierSVG) __obj__[0].Placement = oldPlace - App.ActiveDocument.removeObject(__O__.Label) + FreeCAD.ActiveDocument.removeObject(__O__.Label) - App.activeDocument().recompute() + FreeCAD.activeDocument().recompute() def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing, laserSize): - outputRacine = App.activeDocument().getFileName().rpartition('.')[0] copy_sketchList = sketchList[:] __obj__ = [] currentX = 0.0 @@ -61,8 +88,8 @@ class WindowDialog(): copy_sketchList.pop(index) listSize = len(copy_sketchList) errorCount += 1 - App.ActiveDocument.removeObject(__O__.Label) - App.activeDocument().recompute() + FreeCAD.ActiveDocument.removeObject(__O__.Label) + FreeCAD.activeDocument().recompute() continue if boundingBox.XLength + currentX > plateLength: if boundingBox.YLength + currentY > plateWidth: @@ -81,7 +108,7 @@ class WindowDialog(): continue __obj__.insert(0, __O__) maxY = boundingBox.YLength if boundingBox.YLength > maxY else maxY - __obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0)) + __obj__[0].Placement=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(FreeCAD.Vector(1,0,0),0), FreeCAD.Vector(0,0,0)) if currentX == 0.0: __obj__[0].Placement.Base = FreeCAD.Vector(-boundingBox.XMin + currentX, -boundingBox.YMin + currentY, 0.0) @@ -92,7 +119,7 @@ class WindowDialog(): copy_sketchList.pop(index) listSize = len(copy_sketchList) - App.activeDocument().recompute() + FreeCAD.activeDocument().recompute() index = 0 YBlockCounter = 0 @@ -101,16 +128,16 @@ class WindowDialog(): maxY = 0.0 index = 0 listSize = len(copy_sketchList) - App.activeDocument().recompute() + FreeCAD.activeDocument().recompute() if listSize <= 0 or isSVGFull: - fichierSVG = u"" + outputRacine + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg' - print('Export SVG de : ' + u"" + str(os.path.basename(outputRacine)) + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg') + fichierSVG = u"" + self.outputRacine + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg' + print('Export SVG de : ' + u"" + str(os.path.basename(self.outputRacine)) + '--CALEPINAGE-' + str(SVGNameCounter) + '.svg') importSVG.export(__obj__, fichierSVG) for __i__ in __obj__: - App.ActiveDocument.removeObject(__i__.Label) + FreeCAD.ActiveDocument.removeObject(__i__.Label) - App.activeDocument().recompute() + FreeCAD.activeDocument().recompute() __obj__.clear() maxY = 0.0 index = 0 @@ -149,7 +176,7 @@ class WindowDialog(): FreeCAD.ActiveDocument.recompute() sketchList.append(sk) if hasattr(sv0, 'Name'): - App.ActiveDocument.removeObject(sv0.Name) + FreeCAD.ActiveDocument.removeObject(sv0.Name) if isCalepinage: self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing, laserSize) @@ -157,30 +184,29 @@ class WindowDialog(): self._exportSketchBasic(sketchList) def exportSTL(self, singleMode): - outputRacine = App.activeDocument().getFileName().rpartition('.')[0] __obj__ = [] for selectedObject in FreeCADGui.Selection.getSelectionEx(): __obj__.append(selectedObject.Object) if not singleMode: - filename = u"" + outputRacine + '--' + __obj__[0].Label + '.stl' + filename = u"" + self.outputRacine + '--' + __obj__[0].Label + '.stl' if hasattr(Mesh, "exportOptions"): - options = Mesh.exportOptions(outputRacine) + options = Mesh.exportOptions(self.outputRacine) Mesh.export(__obj__, filename, options) else: Mesh.export(__obj__, filename) print(f'Export STL de : {__obj__[0].Label}.stl') __obj__.clear() if singleMode: - filename = u"" + outputRacine + '--' + __obj__[0].Label + '.stl' if len(__obj__) == 1 else u"" + outputRacine + '.stl' + filename = u"" + self.outputRacine + '--' + __obj__[0].Label + '.stl' if len(__obj__) == 1 else u"" + self.outputRacine + '.stl' if hasattr(Mesh, "exportOptions"): - options = Mesh.exportOptions(outputRacine) + options = Mesh.exportOptions(self.outputRacine) Mesh.export(__obj__, filename, options) else: Mesh.export(__obj__, filename) if len(__obj__) == 1: print(f'Export STL de : {__obj__[0].Label}.stl') else: - print(f'Export STL de {os.path.basename(outputRacine)}.stl') + print(f'Export STL de {os.path.basename(self.outputRacine)}.stl') del __obj__ diff --git a/MultiExport/MultiExport.ui b/MultiExport/MultiExport.ui index de8679c..251211a 100644 --- a/MultiExport/MultiExport.ui +++ b/MultiExport/MultiExport.ui @@ -9,15 +9,21 @@ 0 0 - 300 - 250 + 600 + 500 Multi Exporting - + + + + QAbstractItemView::MultiSelection + + +