FreeCAD: data base names

This commit is contained in:
brothermechanic 2024-04-09 18:08:09 +03:00
parent 3878990c4e
commit 0ecf214e26
No known key found for this signature in database
GPG key ID: 9C59EF9503ACD106
2 changed files with 14 additions and 14 deletions

View file

@ -70,21 +70,21 @@ def export_assembly_trees(doc, clones_dic=None) -> list:
if not root.InList
if root.isDerivedFrom('App::Part')]
tree_files = []
trees = []
for root_locator in root_locators:
dict_tree = {}
freecad_tools.hierarchy_tree(root_locator, dict_tree, clones_dic)
trees.append(dict_tree)
# write file
project_dir = os.path.dirname(doc.FileName)
assembly_tree_path = os.path.join(project_dir, root_locator.Label + '_tree_version.json')
with open(assembly_tree_path, 'w', encoding='utf-8') as json_file:
json.dump(dict_tree, json_file, ensure_ascii=False, indent=4)
logger.info('Assembly tree saved successfully to %s!', assembly_tree_path)
tree_files.append(assembly_tree_path)
logger.info('Saved %s assembly trees!', len(tree_files))
trees_path = os.path.join(project_dir, 'trees.json')
with open(trees_path, 'w', encoding='utf-8') as json_file:
json.dump(trees, json_file, ensure_ascii=False, indent=4)
logger.info('Assembly tree saved successfully to %s!', trees_path)
return tree_files
logger.info('Saved %s assembly trees!', len(trees))
return trees_path
def export_parts_database(
@ -197,7 +197,7 @@ def export_parts_database(
parts_db.append(db_obj)
logger.info('Passed %s parts without errors', len(parts_db))
parts_db_path = os.path.join(project_dir, FreeCAD.ActiveDocument.Label + '_parts_data.json')
parts_db_path = os.path.join(project_dir, 'parts.json')
with open(parts_db_path, 'w', encoding='utf-8') as json_file:
json.dump(parts_db, json_file, ensure_ascii=False, indent=4)
logger.info('Parts Database exported successfully to %s!', parts_db_path)

View file

@ -260,7 +260,6 @@ def hierarchy_tree(obj, dict_tree, clones_dic=None) -> dict:
]
}
'''
# collect type
if obj.isDerivedFrom('Part::Feature'):
if obj.isDerivedFrom('PartDesign::CoordinateSystem'):
@ -274,9 +273,10 @@ def hierarchy_tree(obj, dict_tree, clones_dic=None) -> dict:
# collect name
dict_tree['name'] = obj.Label
# collect base_name
dict_tree['base_name'] = ''
if clones_dic:
if obj.isDerivedFrom('Part::Feature'):
if obj.isDerivedFrom('Part::Feature') and (
not obj.isDerivedFrom('PartDesign::CoordinateSystem')):
dict_tree['base_name'] = obj.Label
for k, v in clones_dic.items():
if obj.Label in v:
dict_tree['base_name'] = k