FreeCAD: data base names
This commit is contained in:
parent
3878990c4e
commit
0ecf214e26
2 changed files with 14 additions and 14 deletions
|
@ -70,21 +70,21 @@ def export_assembly_trees(doc, clones_dic=None) -> list:
|
||||||
if not root.InList
|
if not root.InList
|
||||||
if root.isDerivedFrom('App::Part')]
|
if root.isDerivedFrom('App::Part')]
|
||||||
|
|
||||||
tree_files = []
|
trees = []
|
||||||
for root_locator in root_locators:
|
for root_locator in root_locators:
|
||||||
dict_tree = {}
|
dict_tree = {}
|
||||||
freecad_tools.hierarchy_tree(root_locator, dict_tree, clones_dic)
|
freecad_tools.hierarchy_tree(root_locator, dict_tree, clones_dic)
|
||||||
|
trees.append(dict_tree)
|
||||||
|
# write file
|
||||||
|
project_dir = os.path.dirname(doc.FileName)
|
||||||
|
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)
|
||||||
|
|
||||||
# write file
|
logger.info('Saved %s assembly trees!', len(trees))
|
||||||
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))
|
|
||||||
|
|
||||||
return tree_files
|
return trees_path
|
||||||
|
|
||||||
|
|
||||||
def export_parts_database(
|
def export_parts_database(
|
||||||
|
@ -197,7 +197,7 @@ def export_parts_database(
|
||||||
parts_db.append(db_obj)
|
parts_db.append(db_obj)
|
||||||
|
|
||||||
logger.info('Passed %s parts without errors', len(parts_db))
|
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:
|
with open(parts_db_path, 'w', encoding='utf-8') as json_file:
|
||||||
json.dump(parts_db, json_file, ensure_ascii=False, indent=4)
|
json.dump(parts_db, json_file, ensure_ascii=False, indent=4)
|
||||||
logger.info('Parts Database exported successfully to %s!', parts_db_path)
|
logger.info('Parts Database exported successfully to %s!', parts_db_path)
|
||||||
|
|
|
@ -260,7 +260,6 @@ def hierarchy_tree(obj, dict_tree, clones_dic=None) -> dict:
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# collect type
|
# collect type
|
||||||
if obj.isDerivedFrom('Part::Feature'):
|
if obj.isDerivedFrom('Part::Feature'):
|
||||||
if obj.isDerivedFrom('PartDesign::CoordinateSystem'):
|
if obj.isDerivedFrom('PartDesign::CoordinateSystem'):
|
||||||
|
@ -274,9 +273,10 @@ def hierarchy_tree(obj, dict_tree, clones_dic=None) -> dict:
|
||||||
# collect name
|
# collect name
|
||||||
dict_tree['name'] = obj.Label
|
dict_tree['name'] = obj.Label
|
||||||
# collect base_name
|
# collect base_name
|
||||||
dict_tree['base_name'] = ''
|
|
||||||
if clones_dic:
|
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():
|
for k, v in clones_dic.items():
|
||||||
if obj.Label in v:
|
if obj.Label in v:
|
||||||
dict_tree['base_name'] = k
|
dict_tree['base_name'] = k
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue