I want to select all the lines added on a view to delete them later.
For the moment I can delete when I know the number of the line (here from 1 to 99) but can we make sure to list all the existing lines in order to delete them later?
Below is the snippet of code that the novice that I am trying to modify to then insert it into a slightly more complex macro.
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Numberline As Integer
Sub main()
Numberline = 0
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.ActivateView("Vue de mise en plan1")
Do
Numberline = Numberline + 1
'boolstatus = Part.Extension.SelectByID2("Line", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line" & Numberline, "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Part.EditDelete
Loop While Numberline < 100
End Sub
Try with the following code to see if this works for you:
Option Explicit
Dim swApp As Object
Dim Part As Object
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swSketch As SldWorks.Sketch
Dim vSkSegArr As Variant
Dim vSkSeg As Variant
Dim swSkSeg As SldWorks.SketchSegment
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Numberline As Integer
Dim lNumSegments As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDraw = Part
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.ActivateView("Vue de mise en plan1")
Set swView = swDraw.ActiveDrawingView
lNumSegments = swView.GetLineCount2(1)
If lNumSegments > 0 Then
Set swSketch = swView.GetSketch
vSkSegArr = swSketch.GetSketchSegments
For Each vSkSeg In vSkSegArr
Set swSkSeg = vSkSeg
boolstatus = Part.Extension.SelectByID2(swSkSeg.GetName, "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Part.EditDelete
Next vSkSeg
End If
End Sub
I left the line in question in the code because it was already part of your code but it is useless for the line deletion function, it allows you to set the SW window of the plan to maximum dimension (or to minimum dimension if you replace "swWindowMaximized" with "swWindowMinimized").