Browse Source

Modification du script d'export pour exporter l'assemblage également

master
Youen 2 years ago
parent
commit
96ad63d0fd
  1. BIN
      chaudronnerie/CHO30.FCStd
  2. 60
      tools/export-all-parts.py
  3. 4
      tools/export-all-parts.sh
  4. BIN
      vheliotech.FCStd

BIN
chaudronnerie/CHO30.FCStd

Binary file not shown.

60
tools/export-all-parts.py

@ -1,15 +1,13 @@
freecad_install_path = '/home/youen/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64'
import sys
sys.path.insert(0,freecad_install_path + '/usr/lib')
from pathlib import Path
import os
import FreeCAD as App
import Import
import ImportGui
script_folder = os.path.dirname(__file__)
project_folder = os.path.realpath(script_folder + '/..')
#script_folder = os.path.dirname(__file__)
#project_folder = os.path.realpath(script_folder + '/..')
project_folder = os.getcwd()
output_folder = project_folder + '-STEP'
def convert_file(file_name, output_format):
@ -64,6 +62,49 @@ def convert_file(file_name, output_format):
while len(FreeCAD.listDocuments().values()) > 0:
FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name)
def convert_assembly(file_name, output_format):
print(file_name)
doc = App.open(project_folder + '/' + file_name)
root_objects = []
main_object = None
# remove all objects that are not visible, or not in the TypeId whitelist, because we don't want to export those
need_check_objects = True
while need_check_objects:
need_check_objects = False
for obj in doc.Objects:
if not obj.Visibility or obj.TypeId not in ['Part::Feature', 'Part::FeaturePython', 'PartDesign::Body', 'Part::Mirroring', 'Part::Cut', 'Part::Part2DObjectPython', 'Part::MultiFuse', 'Part::Loft', 'Part::Torus', 'Part::Cylinder', 'App::DocumentObjectGroup', 'App::Part', 'App::Link']:
#print('removing ' + obj.Name + ' ('+obj.Label+')')
doc.removeObject(obj.Name)
need_check_objects = True
break
for obj in doc.Objects:
if len(obj.Parents) == 0:
#print(obj.Label)
root_objects.append(obj)
if obj.Label == doc.Name:
main_object = obj
if main_object is None and len(root_objects) == 1:
main_object = root_objects[0]
if main_object is None:
raise Exception("Can't find main assembly in file " + file_name + " (found " + str(len(root_objects)) + " root object(s), none named like the document " + doc.Name + ")")
output_path = output_folder + '/' + os.path.dirname(file_name) + '/' + Path(file_name).stem + '.' + output_format
output_dir = os.path.dirname(output_path)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
ImportGui.export([main_object], output_path)
# close all documents
while len(FreeCAD.listDocuments().values()) > 0:
FreeCAD.closeDocument(list(FreeCAD.listDocuments().values())[0].Name)
folders = [
'chaudronnerie',
'tubes'
@ -77,3 +118,8 @@ for folder in folders:
print(source_path)
convert_file(source_path, 'step')
convert_assembly('vheliotech.FCStd', 'step')
# exit FreeCAD
FreeCADGui.getMainWindow().close()

4
tools/export-all-parts.sh

@ -0,0 +1,4 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/..
~/dev/FreeCAD-asm3-Daily-Conda-Py3.10-20221128-glibc2.12-x86_64.AppImage tools/export-all-parts.py

BIN
vheliotech.FCStd

Binary file not shown.
Loading…
Cancel
Save