Thank you very much for your help. With your help, I successfully completed the code using ChatGPT. Although this has met my requirements, I still have a question: how should I remove the steps of human-computer interaction until all the holes have added fracture lines between them. Simply put, what I mean is to add a break line between all the holes. Looking forward to your reply.
Imports System.Runtime.InteropServices
Sub Main
' Attempt to cast the active document to a drawing document object
Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
' If the active document is not a drawing document, log debug info and exit the subroutine
If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub
' Prompt the user to select a drawing view, exit the subroutine if none is selected
Dim PickView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to break")
If IsNothing(PickView) Then Exit Sub
' If the selected view already has break operations, ask the user if they wish to continue
If PickView.BreakOperations.Count > 0
If MessageBox.Show("The selected view already has break operations. Would you still like to attempt to break this view?", "Verify Breaks", MessageBoxButtons.YesNo) <> vbYes Then Exit Sub
End If
' Loop to add breaks until the user decides to stop
Dim ContinueAdding As Boolean = True
Do While ContinueAdding
AddBreaksToViewBetweenCentermarks(PickView)
' Prompt the user if they want to continue
ContinueAdding = MessageBox.Show("Do you want to continue adding breaks to the same view?", "Continue?", MessageBoxButtons.YesNo) = vbYes
Loop
End Sub
Sub AddBreaksToViewBetweenCentermarks(dView As DrawingView)
Dim cmCollection As New List(Of Centermark)
For Each cm As Centermark In dView.Parent.Centermarks
' Ensure the centermark is attached to an entity
If Not cm.Attached Then Continue For
Try
' Check if the centermark's attached entity is part of the view we are dealing with
If Not IsNothing(cm.AttachedEntity) AndAlso Not IsNothing(cm.AttachedEntity.Geometry) AndAlso Not IsNothing(cm.AttachedEntity.Geometry.Parent) AndAlso cm.AttachedEntity.Geometry.Parent Is dView Then
cmCollection.Add(cm)
End If
Catch ex As COMException
Logger.Error("COMException occurred: " & ex.Message)
Continue For
End Try
Next
' Sort the collected centermarks by their X-axis coordinates
cmCollection.Sort(Function(a, b) a.Position.X.CompareTo(b.Position.X))
' If less than two centermarks are collected, we cannot add breaks
If cmCollection.Count < 2 Then
Logger.Debug("Not enough Centermarks collected for breaking the view.")
Exit Sub
End If
' Log the number of centermarks collected
Logger.Trace(cmCollection.Count & " Centermarks were collected after sorting.")
' Start adding breaks
Dim BreakCount As Integer = 0
' Loop until the second to last centermark in the list
While BreakCount < cmCollection.Count - 1
' Call the method to add a break between two centermarks
BreakBetweenCentermarks(dView, cmCollection.Item(BreakCount), cmCollection.Item(BreakCount + 1))
' Move to the next pair of centermarks
BreakCount += 1
End While
End Sub
Sub BreakBetweenCentermarks(dView As DrawingView, cm1 As Centermark, cm2 As Centermark)
Try
' Ensure incoming objects are not null
If IsNothing(dView) OrElse IsNothing(cm1) OrElse IsNothing(cm2) Then
Logger.Debug("dView, cm1, or cm2 is Nothing")
Exit Sub
End If
' Check if cm1 and cm2's AttachedEntity and Geometry are valid
If IsNothing(cm1.AttachedEntity) OrElse IsNothing(cm1.AttachedEntity.Geometry) OrElse IsNothing(cm2.AttachedEntity) OrElse IsNothing(cm2.AttachedEntity.Geometry) Then
Logger.Debug("One of the centermarks' attached entities or geometries is Nothing")
Exit Sub
End If
' Check if there are enough elements in the Segments collection
If cm1.AttachedEntity.Geometry.Segments.Count < 1 OrElse cm2.AttachedEntity.Geometry.Segments.Count < 1 Then
Logger.Debug("One of the geometries does not have enough segments")
Exit Sub
End If
Dim StartPoint, EndPoint As Point2d
StartPoint = cm1.Position.Copy
EndPoint = cm2.Position.Copy
' Assuming the first item in Segment exists and has a Radius property
Dim breakoffset1, breakoffset2 As Double
breakoffset1 = cm1.AttachedEntity.Geometry.Segments.Item(1).Geometry.Radius * 10
breakoffset2 = cm2.AttachedEntity.Geometry.Segments.Item(1).Geometry.Radius * 10
Dim offsetVector1, offsetVector2 As Vector2d
offsetVector1 = StartPoint.VectorTo(EndPoint).AsUnitVector.AsVector
offsetVector2 = EndPoint.VectorTo(StartPoint).AsUnitVector.AsVector
offsetVector1.ScaleBy(breakoffset1)
offsetVector2.ScaleBy(breakoffset2)
StartPoint.TranslateBy(offsetVector1)
EndPoint.TranslateBy(offsetVector2)
Dim Gap As Double = .1 'cm
Dim PropegateToParentView As Boolean = False
dView.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, StartPoint, EndPoint, BreakStyleEnum.kStructuralBreakStyle, , Gap, , PropegateToParentView)
Catch ex As Exception
Logger.Error("Error in BreakBetweenCentermarks: " & ex.Message)
End Try
End Sub