Spaces:
Sleeping
Sleeping
Delete convert.py
Browse files- convert.py +0 -68
convert.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
| 1 |
-
# import ezdxf
|
| 2 |
-
|
| 3 |
-
# # Load the DXF file
|
| 4 |
-
# doc = ezdxf.readfile("out.dxf")
|
| 5 |
-
|
| 6 |
-
# # Iterate through all entities in the modelspace
|
| 7 |
-
# for entity in doc.modelspace():
|
| 8 |
-
# entity_type = entity.dxftype() # Get the entity type
|
| 9 |
-
# print(f"Entity Type: {entity_type}")
|
| 10 |
-
|
| 11 |
-
# # Handle different entity types
|
| 12 |
-
# if entity_type == "LINE":
|
| 13 |
-
# print(f"Start: {entity.dxf.start}, End: {entity.dxf.end}")
|
| 14 |
-
# elif entity_type == "CIRCLE":
|
| 15 |
-
# print(f"Center: {entity.dxf.center}, Radius: {entity.dxf.radius}")
|
| 16 |
-
# elif entity_type == "ARC":
|
| 17 |
-
# print(f"Center: {entity.dxf.center}, Radius: {entity.dxf.radius}, Start Angle: {entity.dxf.start_angle}, End Angle: {entity.dxf.end_angle}")
|
| 18 |
-
# elif entity_type == "SPLINE":
|
| 19 |
-
# if entity.control_points:
|
| 20 |
-
# print(f"Control Points: {entity.control_points}")
|
| 21 |
-
# elif entity.fit_points:
|
| 22 |
-
# print(f"Fit Points: {entity.fit_points}")
|
| 23 |
-
# elif entity.knots:
|
| 24 |
-
# print(f"Knots: {entity.knots}")
|
| 25 |
-
# else:
|
| 26 |
-
# print("No control, fit, or knot points found for this SPLINE.")
|
| 27 |
-
# else:
|
| 28 |
-
# print(f"No specific handler for entity type: {entity_type}")
|
| 29 |
-
|
| 30 |
-
import numpy as np
|
| 31 |
-
import ezdxf
|
| 32 |
-
|
| 33 |
-
# Load the DXF file
|
| 34 |
-
doc = ezdxf.readfile("out.dxf")
|
| 35 |
-
|
| 36 |
-
def calculate_distance(p1, p2):
|
| 37 |
-
"""Calculate the distance between two points."""
|
| 38 |
-
return np.linalg.norm(np.array(p1) - np.array(p2))
|
| 39 |
-
|
| 40 |
-
def process_fit_points(fit_points):
|
| 41 |
-
"""Process fit points to calculate distances and bounding box."""
|
| 42 |
-
distances = []
|
| 43 |
-
for i in range(len(fit_points) - 1):
|
| 44 |
-
distances.append(calculate_distance(fit_points[i], fit_points[i + 1]))
|
| 45 |
-
|
| 46 |
-
# Calculate perimeter
|
| 47 |
-
perimeter = sum(distances)
|
| 48 |
-
|
| 49 |
-
# Calculate bounding box
|
| 50 |
-
fit_points_np = np.array(fit_points)
|
| 51 |
-
min_x, min_y = np.min(fit_points_np[:, :2], axis=0)
|
| 52 |
-
max_x, max_y = np.max(fit_points_np[:, :2], axis=0)
|
| 53 |
-
|
| 54 |
-
return {
|
| 55 |
-
"distances": distances,
|
| 56 |
-
"perimeter": perimeter,
|
| 57 |
-
"bounding_box": (min_x, min_y, max_x, max_y)
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
# Iterate through all entities in the modelspace
|
| 61 |
-
for entity in doc.modelspace():
|
| 62 |
-
if entity.dxftype() == "SPLINE" and entity.fit_points:
|
| 63 |
-
print(f"Entity Type: SPLINE")
|
| 64 |
-
fit_points = entity.fit_points
|
| 65 |
-
results = process_fit_points(fit_points)
|
| 66 |
-
print(f"Perimeter: {results['perimeter']}")
|
| 67 |
-
print(f"Bounding Box: {results['bounding_box']}")
|
| 68 |
-
print(f"Distances: {results['distances'][:]}... (showing first 5)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|