I need to delete unnecessary detail views in specified Solidworks drawing, but I need to use late binding. First I try to delete Detail view from feature tree, but then it delete only Detail view leaving sketched circle. Then I delete Detail view in drawing, same result. Then Detail view circle, same result. Last I try delete sketched circle, but it doesn't select certain circle. When this code is compile in Solidworks API, all is working correctly, but when this is compile in Excel VBA, then it does this weird thing. I have suspicion that this is connected with late binding. Any suggestions?
Dim SwApp
On Error Resume Next
Set SwApp = GetObject(, "SldWorks.Application")
'If Solidworks is not started then start it
If Err.Number <> 0 Then
Set SwApp = CreateObject("SldWorks.Application")
End If
SwApp.Visible = True
Dim InitialDrawing2 As Object
Set InitialDrawing2 = SwApp.Opendoc(FormatSketchTemplateFolder & "FormatSketch+Tray.SLDDRW", 3)
Dim Status As Boolean
Status = InitialDrawing2.Extension.SelectByID2("Detail Circle2", "DETAILCIRCLE", 0, 0, 0, False, 0, Nothing, 0)
InitialDrawing2.EditDelete
Status = InitialDrawing2.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
InitialDrawing2.EditDelete
After several hours I found an error. Before selecting circles needs to select certain drawing view
Dim SwApp
On Error Resume Next
Set SwApp = GetObject(, "SldWorks.Application")
'If Solidworks is not started then start it
If Err.Number <> 0 Then
Set SwApp = CreateObject("SldWorks.Application")
End If
SwApp.Visible = True
Dim InitialDrawing2 As Object
Set InitialDrawing2 = SwApp.Opendoc(FormatSketchTemplateFolder & "FormatSketch+Tray.SLDDRW", 3)
Dim Status As Boolean
InitialDrawing2.ActivateView ("Drawing View9")
Status = InitialDrawing2.Extension.SelectByID2("Detail Circle2", "DETAILCIRCLE", 0, 0, 0, False, 0, Nothing, 0)
InitialDrawing2.EditDelete
Status = InitialDrawing2.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
InitialDrawing2.EditDelete