AnsweredAssumed Answered

Delete Top Level Macro

Question asked by Mark Coville on Apr 28, 2014
Latest reply on Apr 29, 2014 by Mark Coville



Does anyone have a macro that deletes the top level of what is selected. We just upgraded from SW2011 to SW2014 and this new delete functionality is not the best thing for us .(especially with EPDM) Here is what I have so far. I don't know how to select the top level of each component. Any help would be great




Dim swApp               As SldWorks.SldWorks
Dim swModel             As SldWorks.ModelDoc2
Dim swSelMgr            As SldWorks.SelectionMgr
Dim swSelComp           As SldWorks.Component2
Dim NewObjToSelect      As Object
Dim GeneralSelObj       As Object
Dim swParent            As Object
Dim selObjectsCount     As Integer
Dim i                   As Integer
Dim CurSelCount         As Long
Dim boolstatus          As Boolean

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
CurSelCount = 1
selObjectsCount = swSelMgr.GetSelectedObjectCount
For i = 1 To selObjectsCount
    Set GeneralSelObj = swSelMgr.GetSelectedObject(CurSelCount)
    Set swSelComp = swSelMgr.GetSelectedObjectsComponent(CurSelCount)
    Set NewObjToSelect = swSelComp.GetParent
    If Not NewObjToSelect Is Nothing Then
    swSelMgr.DeSelect CurSelCount
    bRet = NewObjToSelect.Select(True)
    CurSelCount = CurSelCount + 1
    End If
End Sub