From f8771be49a526d2bddb27fcedea0f26b6aa095a0 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 1 Mar 2019 19:58:11 +0100 Subject: [PATCH] Material, card writer, add parameter to switch off group section writing (it is how material cards look like ATM) --- src/Mod/Material/Material.py | 7 +++++-- src/Mod/Material/importFCMat.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Mod/Material/Material.py b/src/Mod/Material/Material.py index ce79b9bd8a..32c6e4d1f4 100644 --- a/src/Mod/Material/Material.py +++ b/src/Mod/Material/Material.py @@ -139,13 +139,16 @@ def read_cards_from_path(cards_path): return mat_cards -def write_cards_to_path(cards_path, cards_data): +def write_cards_to_path(cards_path, cards_data, write_group_section=True): from importFCMat import write from os.path import join for card_data in cards_data: card_path = join(cards_path, (card_data['CardName'] + '.FCMat')) print(card_path) - write(card_path, card_data) + if write_group_section is True: + write(card_path, card_data, True) + else: + write(card_path, card_data, False) if __name__ == '__main__': diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index 4f35a0ba89..bde809aef4 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -138,7 +138,7 @@ def read(filename): return d -def write(filename, dictionary): +def write(filename, dictionary, write_group_section=True): "writes the given dictionary to the given file" # sort the data into sections @@ -194,11 +194,16 @@ def write(filename, dictionary): f.write("; file produced by FreeCAD" + rev + "\n") f.write("\n") # write sections + # write standard FCMat section if write group section parameter is set to False + if write_group_section is False: + f.write("[FCMat]\n") for s in contents: if s["keyname"] != "Meta": # if the section has no contents, we don't write it if len(s) > 1: - f.write("[" + s["keyname"] + "]\n") + # only write group section if write group section parameter is set to True + if write_group_section is True: + f.write("[" + s["keyname"] + "]\n") for k, i in s.items(): if (k != "keyname" and i != '') or k == "Name": # use only keys which are not empty and the name even if empty @@ -206,5 +211,6 @@ def write(filename, dictionary): f.write(k + " = " + i + "\n") else: f.write(k + " = " + i.encode('utf-8') + "\n") - f.write("\n") + if write_group_section is True: + f.write("\n") f.close()