SOLIDWORKS macro to break all external references for components

Edit ArticleEdit Article
More 'Goodies'

This example will break all external references for all components in the active assembly using SOLIDWORKS API.

Command to break all external references
Command to break all external references

Dim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc

Sub main()

    Set swApp = Application.SldWorks
    Set swAssy = swApp.ActiveDoc
    If Not swAssy Is Nothing Then
        swAssy.ResolveAllLightWeightComponents True
        Dim vComps As Variant
        Dim swComp As SldWorks.Component2
        Dim swCompModel As SldWorks.ModelDoc2
        vComps = swAssy.GetComponents(False)
        Dim i As Integer
        For i = 0 To UBound(vComps)
            Set swComp = vComps(i)
            Set swCompModel = swComp.GetModelDoc2
            If Not swCompModel Is Nothing Then
                swCompModel.Extension.BreakAllExternalFileReferences2 False
            End If
        MsgBox "Please open assembly"
    End If
End Sub


All articles and code at CodeStack are now open-source and hosted on GitHub. If you want to contribute by modifying existing articles and code snippets, submitting new ones, reporting errors and bugs etc. please follow this blog post for more information. We appreciate any contribution.

Product of Xarial Product of Xarial