MACRO LIBRARY

Delete part from sub-assembly

Free public access. No account or subscription required.

Files

Delete part from sub-assembly

Code

'When a part contained within a sub-assembly is deleted, that sub-assembly must be edit _
    mode otherwise the entire sub-assy is deleted. This macro demonstrates how to delete _
    a selected component residing within a sub-assembly without deleting the whole _
    sub-assembly
    
'Preconditions: component within a sub-assembly is selected
'Result: only the selected component is deleted
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim swParentComp As SldWorks.Component2
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    Set swSelMgr = swModel.SelectionManager
    Set swComp = swSelMgr.GetSelectedObject6(1, -1)
    Set swParentComp = swComp.GetParent
    swParentComp.Select4 False, Nothing, False
    swAssy.EditAssembly
    swComp.Select4 False, Nothing, False
    swModel.EditDelete
    swAssy.EditAssembly
End Sub