finished load and save methods
This commit is contained in:
parent
9cc8cd49c0
commit
84e7618b91
|
|
@ -26,6 +26,9 @@ class ObjectListItem(QWidget):
|
|||
def get_value(self):
|
||||
return self.spinbox.value()
|
||||
|
||||
def set_value(self, value):
|
||||
self.spinbox.setValue(value)
|
||||
|
||||
|
||||
class WindowDialog():
|
||||
def __init__(self):
|
||||
|
|
@ -35,8 +38,9 @@ class WindowDialog():
|
|||
self.form = FreeCADGui.PySideUic.loadUi(self.ui_file)
|
||||
self.connect_widgets()
|
||||
self.populate_selector_list()
|
||||
self.listVarSets()
|
||||
|
||||
FreeCADGui.Selection.addObserver(self.on_selection_changed)
|
||||
# FreeCADGui.Selection.addObserver(self.on_selection_changed)
|
||||
|
||||
self.form.show()
|
||||
|
||||
|
|
@ -44,6 +48,7 @@ class WindowDialog():
|
|||
def connect_widgets(self):
|
||||
self.form.pushButtonExport.pressed.connect(self.export)
|
||||
self.form.pushButtonSave.pressed.connect(self.saveVarSet)
|
||||
self.form.pushButtonLoad.pressed.connect(self.loadVarSet)
|
||||
|
||||
|
||||
def populate_selector_list(self):
|
||||
|
|
@ -51,7 +56,7 @@ class WindowDialog():
|
|||
FreeCADGui.Selection.clearSelection()
|
||||
|
||||
for obj in FreeCAD.ActiveDocument.Objects:
|
||||
if obj.Label.endswith("-SVG") or obj.Label.endswith("-STL"):
|
||||
if obj.Label.endswith("_SVG") or obj.Label.endswith("_STL"):
|
||||
item = QListWidgetItem()
|
||||
widget = ObjectListItem(obj)
|
||||
|
||||
|
|
@ -62,21 +67,6 @@ class WindowDialog():
|
|||
item.setSelected(True)
|
||||
|
||||
|
||||
def on_selection_changed(self, doc, objects):
|
||||
for index in range(self.form.listWidgetSelector.count()):
|
||||
item = self.form.listWidgetSelector.item(index)
|
||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||
item.setSelected(False)
|
||||
|
||||
for obj in FreeCADGui.Selection.getSelection():
|
||||
for index in range(self.form.listWidgetSelector.count()):
|
||||
item = self.form.listWidgetSelector.item(index)
|
||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||
if widget.obj == obj:
|
||||
item.setSelected(True)
|
||||
break
|
||||
|
||||
|
||||
def createFolder(self):
|
||||
date = datetime.today().strftime('%Y-%m-%d')
|
||||
time = datetime.today().strftime('%H:%M:%S')
|
||||
|
|
@ -94,7 +84,7 @@ class WindowDialog():
|
|||
return folderPath
|
||||
|
||||
|
||||
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- #
|
||||
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse_SVG" de Gauthier Brière -------- #
|
||||
|
||||
def exportSketchBasic(self, sketchList):
|
||||
for __O__ in sketchList:
|
||||
|
|
@ -297,9 +287,9 @@ class WindowDialog():
|
|||
|
||||
if widget.obj == obj:
|
||||
count = widget.get_value()
|
||||
if obj.Label.endswith("-SVG"):
|
||||
if obj.Label.endswith("_SVG"):
|
||||
svgList.append((obj.Label, obj, count))
|
||||
elif obj.Label.endswith("-STL"):
|
||||
elif obj.Label.endswith("_STL"):
|
||||
stlList.append((obj.Label, obj, count))
|
||||
break
|
||||
|
||||
|
|
@ -310,28 +300,89 @@ class WindowDialog():
|
|||
self.exportSTL(isCombine, stlList)
|
||||
|
||||
|
||||
def saveVarSet(self, varSetName = "TestVarSet"):
|
||||
def saveVarSet(self):
|
||||
varSetName = self.form.saveTextValue.text()
|
||||
varSet = FreeCAD.ActiveDocument.addObject("App::VarSet", varSetName)
|
||||
self.form.saveTextValue.setText("")
|
||||
|
||||
for obj in FreeCADGui.Selection.getSelection():
|
||||
for obj in FreeCAD.ActiveDocument.Objects:
|
||||
count = 1
|
||||
for index in range(self.form.listWidgetSelector.count()):
|
||||
item = self.form.listWidgetSelector.item(index)
|
||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||
|
||||
if widget.obj == obj:
|
||||
count = widget.get_value()
|
||||
break
|
||||
|
||||
varSet.addProperty("App::PropertyStringList", obj.Name)
|
||||
if obj.Label.endswith("-SVG"):
|
||||
setattr(varSet, obj.Name, ("SVG", str(count)))
|
||||
if obj.Label.endswith("_SVG") or obj.Label.endswith("_STL"):
|
||||
varSet.addProperty("App::PropertyStringList", obj.Label, "MultiExport")
|
||||
if obj.Label.endswith("_SVG"):
|
||||
setattr(varSet, obj.Label, ("SVG", str(count)))
|
||||
else:
|
||||
setattr(varSet, obj.Name, ("STL", str(count)))
|
||||
setattr(varSet, obj.Label, ("STL", str(count)))
|
||||
|
||||
self.listVarSets()
|
||||
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
|
||||
# def loadVarSet(self, varSetName = "TestVarSet", count = 1):
|
||||
'''def loadVarSet(self):
|
||||
# faire lien entre VarSet et liste
|
||||
# refresh a la fin ?
|
||||
|
||||
varSetName = self.form.loadDropDown.currentText()
|
||||
varSet = FreeCAD.ActiveDocument.getObject(varSetName)
|
||||
for prop in varSet.PropertiesList:
|
||||
if varSet.getGroupOfProperty(prop) == "MultiExport":
|
||||
print(f"{prop}: {getattr(varSet, prop)}")
|
||||
|
||||
for index in range(self.form.listWidgetSelector.count()):
|
||||
item = self.form.listWidgetSelector.item(index)
|
||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||
|
||||
if widget.obj == obj:
|
||||
count = widget.get_value()
|
||||
break'''
|
||||
|
||||
def loadVarSet(self):
|
||||
varSetName = self.form.loadDropDown.currentText()
|
||||
if not varSetName:
|
||||
return
|
||||
|
||||
varSet = FreeCAD.ActiveDocument.getObject(varSetName)
|
||||
if not varSet:
|
||||
return
|
||||
|
||||
values_dict = {}
|
||||
for prop in varSet.PropertiesList:
|
||||
if varSet.getGroupOfProperty(prop) == "MultiExport":
|
||||
val = getattr(varSet, prop)
|
||||
if isinstance(val, tuple) or isinstance(val, list):
|
||||
try:
|
||||
count = int(val[1])
|
||||
values_dict[prop] = count
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for index in range(self.form.listWidgetSelector.count()):
|
||||
item = self.form.listWidgetSelector.item(index)
|
||||
widget = self.form.listWidgetSelector.itemWidget(item)
|
||||
if widget.obj.Label in values_dict:
|
||||
widget.set_value(values_dict[widget.obj.Label])
|
||||
|
||||
|
||||
|
||||
def listVarSets(self):
|
||||
varSetsList = [obj for obj in FreeCAD.ActiveDocument.Objects if obj.TypeId == "App::VarSet"]
|
||||
|
||||
self.form.loadDropDown.clear()
|
||||
|
||||
self.form.loadDropDown.setPlaceholderText("Select a VarSet")
|
||||
|
||||
for varSet in varSetsList:
|
||||
self.form.loadDropDown.addItem(varSet.Label, varSet.Name)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -180,20 +180,48 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="pushButtonExport">
|
||||
<property name="text">
|
||||
<string notr="true">Exporter</string>
|
||||
</property>
|
||||
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2" colspan="2">
|
||||
<item row="7" column="0" colspan="3">
|
||||
<widget class="QWidget" name="containerWidget">
|
||||
<layout class="QGridLayout" name="gridLayout3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButtonSave">
|
||||
<property name="text">
|
||||
<string notr="true">Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pushButtonLoad">
|
||||
<property name="text">
|
||||
<string notr="true">Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="saveTextValue">
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
<property name="maximumWidth">
|
||||
<number>160</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QComboBox" name="loadDropDown">
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pushButtonExport">
|
||||
<property name="text">
|
||||
<string notr="true">Exporter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
Loading…
Reference in a new issue