RCG Pipeline Release with Docs
This commit is contained in:
parent
df0fb32592
commit
3878990c4e
26 changed files with 2127 additions and 54 deletions
|
@ -48,15 +48,15 @@ logging.basicConfig(level=logging.INFO)
|
|||
def export_assembly_trees(doc, clones_dic=None) -> list:
|
||||
''' Read FreeCAD .FCStd hierarchy and store it to assembly JSON config files. '''
|
||||
# determine root locators
|
||||
lcs_root_points = []
|
||||
default_origins = []
|
||||
for obj in doc.Objects:
|
||||
if obj.isDerivedFrom('PartDesign::CoordinateSystem'):
|
||||
if (hasattr(obj, 'Robossembler_DefaultOrigin')
|
||||
and getattr(obj, 'Robossembler_DefaultOrigin')):
|
||||
lcs_root_points.append(obj)
|
||||
if len(lcs_root_points) > 1:
|
||||
default_origins.append(obj)
|
||||
if len(default_origins) > 1:
|
||||
root_locators = []
|
||||
for lcs in lcs_root_points:
|
||||
for lcs in default_origins:
|
||||
if hasattr(lcs, 'Robossembler_RootLocator'):
|
||||
root_locators.append(getattr(lcs, 'Robossembler_DefaultOrigin'))
|
||||
else:
|
||||
|
@ -68,23 +68,23 @@ def export_assembly_trees(doc, clones_dic=None) -> list:
|
|||
root_locators = [
|
||||
root for root in doc.Objects
|
||||
if not root.InList
|
||||
if root .isDerivedFrom('App::Part')]
|
||||
if root.isDerivedFrom('App::Part')]
|
||||
|
||||
config_files = []
|
||||
tree_files = []
|
||||
for root_locator in root_locators:
|
||||
dict_tree = {}
|
||||
freecad_tools.hierarchy_tree(root_locator, dict_tree, clones_dic)
|
||||
|
||||
# write file
|
||||
main_file_dir = os.path.dirname(doc.FileName)
|
||||
assembly_tree_path = os.path.join(main_file_dir, f'{root_locator.Label}.json')
|
||||
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)
|
||||
config_files.append(assembly_tree_path)
|
||||
logger.info('Saved %s assembly trees!', len(config_files))
|
||||
tree_files.append(assembly_tree_path)
|
||||
logger.info('Saved %s assembly trees!', len(tree_files))
|
||||
|
||||
return config_files
|
||||
return tree_files
|
||||
|
||||
|
||||
def export_parts_database(
|
||||
|
@ -94,9 +94,7 @@ def export_parts_database(
|
|||
Collect parts database and export as JSON config file
|
||||
[
|
||||
{
|
||||
'type': '',
|
||||
'name': '',
|
||||
'attributes': [],
|
||||
'part_path': '',
|
||||
'material_path': ''
|
||||
},
|
||||
|
@ -104,13 +102,19 @@ def export_parts_database(
|
|||
]
|
||||
'''
|
||||
# path directory
|
||||
main_file_dir = os.path.dirname(doc.FileName)
|
||||
parts_dir = os.path.join(main_file_dir, 'parts')
|
||||
if os.path.exists(parts_dir):
|
||||
shutil.rmtree(parts_dir)
|
||||
os.makedirs(parts_dir)
|
||||
project_dir = os.path.dirname(doc.FileName)
|
||||
materials_dir = os.path.join(project_dir, 'parts', 'materials')
|
||||
if os.path.exists(materials_dir):
|
||||
shutil.rmtree(materials_dir)
|
||||
os.makedirs(materials_dir)
|
||||
else:
|
||||
os.makedirs(parts_dir)
|
||||
os.makedirs(materials_dir)
|
||||
objects_dir = os.path.join(project_dir, 'parts', 'objects')
|
||||
if os.path.exists(objects_dir):
|
||||
shutil.rmtree(objects_dir)
|
||||
os.makedirs(objects_dir)
|
||||
else:
|
||||
os.makedirs(objects_dir)
|
||||
|
||||
# collect all materials
|
||||
fem_mats = [fem_mat for fem_mat in doc.Objects
|
||||
|
@ -140,7 +144,11 @@ def export_parts_database(
|
|||
logger.warning('Part has non solid shape! Please check %s', obj.Label)
|
||||
continue
|
||||
|
||||
db_obj = {'type': 'PART'}
|
||||
db_obj = {
|
||||
'name': '',
|
||||
'part_path': '',
|
||||
'material_path': ''
|
||||
}
|
||||
|
||||
db_obj['name'] = obj.Label
|
||||
if clones_dic:
|
||||
|
@ -154,7 +162,7 @@ def export_parts_database(
|
|||
for attr in robossembler_attrs:
|
||||
db_obj['attributes'].append({attr: getattr(obj, attr)})
|
||||
|
||||
part_path = os.path.join(parts_dir, db_obj['name'] + '.stl')
|
||||
part_path = os.path.join(objects_dir, db_obj['name'] + '.stl')
|
||||
if os.path.exists(part_path):
|
||||
# this is clone
|
||||
continue
|
||||
|
@ -167,7 +175,7 @@ def export_parts_database(
|
|||
# export to stl files
|
||||
#Mesh.export([mesh_from_shape], part_path, tolerance=linear_deflection)
|
||||
mesh_from_shape.Mesh.write(part_path)
|
||||
db_obj['part_path'] = os.path.relpath(part_path, main_file_dir)
|
||||
db_obj['part_path'] = os.path.relpath(part_path, project_dir)
|
||||
logger.info('Part %s exported to stl file %s.', obj.Label, part_path)
|
||||
|
||||
# find linked material path
|
||||
|
@ -176,15 +184,20 @@ def export_parts_database(
|
|||
for ref in fem_mat.References
|
||||
if ref[0].Label == obj.Label]
|
||||
if fem_mat_name:
|
||||
for material_path in material_paths:
|
||||
if fem_mat_name[0] in material_path:
|
||||
db_obj['material_path'] = material_path
|
||||
for source_path in material_paths:
|
||||
if fem_mat_name[0] not in source_path:
|
||||
continue
|
||||
material_path = os.path.join(
|
||||
materials_dir, os.path.basename(source_path))
|
||||
if not os.path.exists(material_path):
|
||||
shutil.copy2(source_path, material_path)
|
||||
db_obj['material_path'] = os.path.relpath(material_path, project_dir)
|
||||
|
||||
# append to database
|
||||
parts_db.append(db_obj)
|
||||
|
||||
logger.info('Passed %s parts without errors', len(parts_db))
|
||||
parts_db_path = os.path.join(main_file_dir, f'{FreeCAD.ActiveDocument.Label}.FCStd.json')
|
||||
parts_db_path = os.path.join(project_dir, FreeCAD.ActiveDocument.Label + '_parts_data.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)
|
||||
|
@ -218,9 +231,8 @@ def publish_project_database(doc=FreeCAD.getDocument(FreeCAD.ActiveDocument.Labe
|
|||
#doc.saveAs(u"/<file_dir>/<file_name>")
|
||||
|
||||
clones_dic = freecad_tools.collect_clones(doc)
|
||||
|
||||
export_assembly_trees(doc, clones_dic)
|
||||
export_parts_database(doc, clones_dic, **tesselation_params)
|
||||
tree_files = export_assembly_trees(doc, clones_dic)
|
||||
parts_data = export_parts_database(doc, clones_dic, **tesselation_params)
|
||||
|
||||
logger.info('FreeCAD document %s published!', doc.Label)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue