Attaching prt-asm when opening a WWTP

Hello colleagues,

Quick question, is it possible to fix all the parts and assemblies and sub-assemblies simply after opening a step, for the 1st level no worries but then you have to deploy and open to fix. There must surely be something but I can't find it.

Thanks in advance

1 Like

Hello
I use the macro as an attachment ;-)

Here's the code:

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()
    Dim swModel As ModelDoc2
    Dim swAssy As AssemblyDoc
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    TransverseComponents swAssy
    swApp.SendMsgToUser "Terminé" & Chr(10) & ":-)"
    swAssy.ForceRebuild2 (True)
End Sub

Sub TransverseComponents(swAssy As AssemblyDoc)
    Dim vComponents As Variant
    Dim i As Integer
    Dim swComponent As Component2
    Dim swModel As ModelDoc2
    Dim swAssembly As AssemblyDoc
    
    vComponents = swAssy.GetComponents(True)
    For i = 0 To UBound(vComponents)
        Set swComponent = vComponents(i)
        Set swModel = swComponent.GetModelDoc2
        Debug.Print swComponent.Name2
        swComponent.Select4 False, Nothing, False
        swAssy.FixComponent
        If Not swModel Is Nothing Then
            If swModel.GetType = swDocASSEMBLY Then
                Set swAssembly = swModel
                TransverseComponents swAssembly
            End If
        End If
    Next i
End Sub

 


fixer_ensembles_et_sous_ensembles.swp
2 Likes

The class, thank you. It works great.

2 Likes

Good evening

I just used it with SW19 and the parts are not fixed, only the sets and s/sets.
Did I miss something, is it a version problem or is it normal?

@stefbeno, during my first uses I hadn't paid attention but after running it two or three times the PRT was fixed.  Maybe a small bug due to the new versions because I'm in 2020. Maybe see with @remrem if he has also noticed this bug?

1 Like