FreeCAD usage
use sketcher, draw on x-z plane
use constrain
snap to grid
select lines from combo view > task > elements
output in the format for *.poly in dynearthrsol2D
import FreeCAD as App
import FreeCADGui as Gui
def convert_lines_to_points():
points = {} # Dictionary to store unique points
connectivity = {} # Dictionary to store connectivity between points
point_id = 0 # Start point ID from 0
connectivity_id = 0 # Start connectivity ID from 0
# Select the lines you want to convert in the GUI
lines = Gui.Selection.getSelection() # Assuming lines are selected
if lines:
total_points = 0
total_segments = 0
for line in lines:
segments = line.Geometry # Get all line segments
total_segments += len(segments)
for segment in segments:
start_point = segment.StartPoint
end_point = segment.EndPoint
# Check if start point already exists
if (start_point.x, start_point.y) in points.values():
start_id = next(key for key, value in points.items() if value == (start_point.x, start_point.y))
else:
points[point_id] = (start_point.x, start_point.y)
start_id = point_id
point_id += 1
# Check if end point already exists
if (end_point.x, end_point.y) in points.values():
end_id = next(key for key, value in points.items() if value == (end_point.x, end_point.y))
else:
points[point_id] = (end_point.x, end_point.y)
end_id = point_id
point_id += 1
# Add connectivity between points
connectivity[connectivity_id] = (start_id, end_id)
connectivity_id += 1
total_points = len(points)
# Check and assign positions based on connectivity
for conn_id, (point1_id, point2_id) in connectivity.items():
point1_x, point1_y = points[point1_id]
point2_x, point2_y = points[point2_id]
position = 0
# note that e3 is added by myself.
if point1_y == 0 and point2_y == 0:
position |= 32 # Set bit 5 to 1
elif point1_y == -10 and point2_y == -10:
position |= 16 # Set bit 4 to 1
if point1_x == 0 and point2_x == 0:
position |= 1 # Set bit 0 to 1
if point1_x == 100 and point2_x == 100:
position |= 2 # Set bit 1 to 1
# Update connectivity with position information
connectivity[conn_id] = (point1_id, point2_id, position)
# Print information about the points and connectivity
print(f"#### node coordinates # npoints ndims 0 0####\n# npoints ndims 0 0 \n#Total Points:\n {total_points} 2 0 0 ")
# Print points
print("#PointID, CoordinateX, CoordinateY")
for point_id, coordinates in points.items():
print(f"{point_id} {coordinates[0]}e3 {coordinates[1]}e3 ")
# Print connectivity with position
print(f"#### segments ####\n#Total Segments:\n {total_segments} 1")
print("\n#ConnectivityID, Point1ID, Point2ID, Position")
for conn_id, (point1_id, point2_id, position) in connectivity.items():
print(f"{conn_id} {point1_id} {point2_id} {position}")
else:
print("No lines selected.")
convert_lines_to_points()
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up