Material, card writer, add parameter to switch off group section writing (it is how material cards look like ATM)
This commit is contained in:
@@ -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__':
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user