Model základny hotov - CAD freeze

This commit is contained in:
Tomáš Batelka 2025-01-04 03:52:32 +01:00
parent 728dcef89c
commit 5bad788801
56 changed files with 25 additions and 28 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -5,14 +5,15 @@ import FreeCAD # type: ignore
import Mesh # type: ignore import Mesh # type: ignore
# Define the project root directory # Define the project root directory
project_root = os.path.abspath( project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)
)
# Define the directories for CAD files and 3MF export files # Define the directories for CAD files and 3MF export files
printed_cad_dir = os.path.join(project_root, "cad", "printed") printed_cad_dir = os.path.join(project_root, "cad", "printed")
printed_3mf_dir = os.path.join(project_root, "3mf") printed_3mf_dir = os.path.join(project_root, "3mf")
# Create the 3mf directory if it doesn't exist
os.makedirs(printed_3mf_dir, exist_ok=True)
# List to keep track of files that failed to export # List to keep track of files that failed to export
failed_files = [] failed_files = []
@ -23,40 +24,36 @@ for root, dirs, files in os.walk(printed_cad_dir):
# Absolute path of the CAD file # Absolute path of the CAD file
file_path = os.path.join(root, file) file_path = os.path.join(root, file)
# Abslute path for the exported 3MF file FreeCAD.Console.PrintMessage(f"\nProcessing {file_path}\n")
output_path = os.path.join(
printed_3mf_dir, os.path.relpath(file_path, printed_cad_dir)
).replace(".FCStd", ".3mf")
# Create the output directory if it doesn't already exist # Open the FreeCAD document
os.makedirs(os.path.dirname(output_path), exist_ok=True)
FreeCAD.Console.PrintMessage(f"\nExporting {file_path}\n")
# Open the FreeCAD document and recompute it
doc = FreeCAD.openDocument(file_path) doc = FreeCAD.openDocument(file_path)
FreeCAD.setActiveDocument(doc.Name) FreeCAD.setActiveDocument(doc.Name)
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
# Get the body object from the document # Iterate over all objects in the document
body = doc.getObject("Body") for obj in doc.Objects:
if body is None: # Check if the object is Std_Part
FreeCAD.Console.PrintError(f"No 'Body' found in {file}\n") if obj.TypeId == 'App::Part':
FreeCAD.closeDocument(doc.Name) # Construct the output path for the 3MF file using the label
failed_files.append(file_path) output_path = os.path.join(
continue printed_3mf_dir, os.path.relpath(root, printed_cad_dir), f"{obj.Label}.3mf"
)
# Create the output directory if it doesn't already exist
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# Try to export the body to a 3MF file try:
try: # Export the part to a 3MF file
Mesh.export([body], output_path) Mesh.export([obj], output_path)
except Exception as e: FreeCAD.Console.PrintMessage(f"Exported {obj.Label} to {output_path}\n")
FreeCAD.Console.PrintError(f"Error exporting {file}: {e}\n") except Exception as e:
failed_files.append(file_path) FreeCAD.Console.PrintError(f"Error exporting {obj.Label}: {e}\n")
failed_files.append(file_path)
# Close the FreeCAD document # Close the FreeCAD document
FreeCAD.closeDocument(doc.Name) FreeCAD.closeDocument(doc.Name)
# Print the result of the export and the files that failed # Print the result of the export process
if failed_files: if failed_files:
FreeCAD.Console.PrintError("\nThe following files failed to export:\n") FreeCAD.Console.PrintError("\nThe following files failed to export:\n")
for file in failed_files: for file in failed_files: