1
0
Fork 0
mirror of https://github.com/vofy/fekt-scara.git synced 2025-05-07 18:51:00 +02:00

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
3mf/base
cad
scripts

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
# Define the project root directory
project_root = os.path.abspath(
os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)
)
project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
# Define the directories for CAD files and 3MF export files
printed_cad_dir = os.path.join(project_root, "cad", "printed")
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
failed_files = []
@ -23,43 +24,39 @@ for root, dirs, files in os.walk(printed_cad_dir):
# Absolute path of the CAD file
file_path = os.path.join(root, file)
# Abslute path for the exported 3MF file
output_path = os.path.join(
printed_3mf_dir, os.path.relpath(file_path, printed_cad_dir)
).replace(".FCStd", ".3mf")
FreeCAD.Console.PrintMessage(f"\nProcessing {file_path}\n")
# Create the output directory if it doesn't already exist
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
# Open the FreeCAD document
doc = FreeCAD.openDocument(file_path)
FreeCAD.setActiveDocument(doc.Name)
FreeCAD.ActiveDocument.recompute()
# Get the body object from the document
body = doc.getObject("Body")
if body is None:
FreeCAD.Console.PrintError(f"No 'Body' found in {file}\n")
FreeCAD.closeDocument(doc.Name)
failed_files.append(file_path)
continue
# Iterate over all objects in the document
for obj in doc.Objects:
# Check if the object is Std_Part
if obj.TypeId == 'App::Part':
# Construct the output path for the 3MF file using the label
output_path = os.path.join(
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:
Mesh.export([body], output_path)
except Exception as e:
FreeCAD.Console.PrintError(f"Error exporting {file}: {e}\n")
failed_files.append(file_path)
try:
# Export the part to a 3MF file
Mesh.export([obj], output_path)
FreeCAD.Console.PrintMessage(f"Exported {obj.Label} to {output_path}\n")
except Exception as e:
FreeCAD.Console.PrintError(f"Error exporting {obj.Label}: {e}\n")
failed_files.append(file_path)
# Close the FreeCAD document
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:
FreeCAD.Console.PrintError("\nThe following files failed to export:\n")
for file in failed_files:
FreeCAD.Console.PrintError(f" - {file}\n")
else:
FreeCAD.Console.PrintMessage("\nAll files have been exported successfully.\n")
FreeCAD.Console.PrintMessage("\nAll files have been exported successfully.\n")