Macro activation bar blocking all parts from an ASM

Hello

being really bad at macro; I post a Marco of @jeromeP to be made to lower the recovery bar from an assembly to all the parts.

I would have liked to know if it is possible to achieve the same thing but with the blocking bar that will lock the functions of the PRTs and thus save reconstruction time when opening the ASM

 

thank you in advance :-)

Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
    Dim swModel As SldWorks.ModelDoc2
    Dim swConf As SldWorks.Configuration
    Dim swRootComp As SldWorks.Component2
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swConf = swModel.GetActiveConfiguration
    Set swRootComp = swConf.GetRootComponent3(True)
    TraverseComponent swRootComp
End Sub

Sub TraverseComponent(swComp As SldWorks.Component2)
    Dim vChildComp As Variant
    Dim swChildComp As SldWorks.Component2
    Dim swCompConfig As SldWorks.Configuration
    Dim i As Long
    vChildComp = swComp.GetChildren
    For i = 0 To UBound(vChildComp)
        Set swChildComp = vChildComp(i)
        TraverseComponent swChildComp
    Next i
    RollBack swComp
End Sub

Sub RollBack(swComp As SldWorks.Component2)
    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swComp.GetModelDoc2
    swApp.ActivateDoc3 swComp.Name2, False, swRebuildOnActivation_e.swRebuildActiveDoc, Empty
    If swModel.GetType <> swDocumentTypes_e.swDocPART Then Exit Sub
    swModel.FeatureManager.EditRollback swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, Empty
    swModel.EditRebuild3
    swModel.Save3 swSaveAsOptions_e.swSaveAsOptions_Silent, Empty, Empty
    swApp.CloseDoc swModel.GetPathName
End Sub

 

You actually have to mount it with swMoveFreezeBarToTop:

Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
    Dim swModel As SldWorks.ModelDoc2
    Dim swConf As SldWorks.Configuration
    Dim swRootComp As SldWorks.Component2
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swConf = swModel.GetActiveConfiguration
    Set swRootComp = swConf.GetRootComponent3(True)
    TraverseComponent swRootComp
End Sub

Sub TraverseComponent(swComp As SldWorks.Component2)
    Dim vChildComp As Variant
    Dim swChildComp As SldWorks.Component2
    Dim swCompConfig As SldWorks.Configuration
    Dim i As Long
    vChildComp = swComp.GetChildren
    For i = 0 To UBound(vChildComp)
        Set swChildComp = vChildComp(i)
        TraverseComponent swChildComp
    Next i
    RollBack swComp
End Sub

Sub RollBack(swComp As SldWorks.Component2)
    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swComp.GetModelDoc2
    swApp.ActivateDoc3 swComp.Name2, False, swRebuildOnActivation_e.swRebuildActiveDoc, Empty
    If swModel.GetType <> swDocumentTypes_e.swDocPART Then Exit Sub
    swModel.FeatureManager.EditFreeze2 swMoveFreezeBarTo_e.swMoveFreezeBarToTop, Empty, True, True
    swModel.EditRebuild3
    swModel.Save3 swSaveAsOptions_e.swSaveAsOptions_Silent, Empty, Empty
    swApp.CloseDoc swModel.GetPathName
End Sub

 

1 Like

Hello ac cobra 427 how are you??

Look here you should find what you are looking for.

https://www.lynkoa.com/forum/solidworks/actionner-la-barre-de-blocage-macro-sur-toutes-pi%C3%A8ces-dun-assemblage?page=0#answer-1083726

may the force be with you.

 

1 Like

Hello ac cobra 427,

And since there are several ways to do it, here is my contribution:

Option Explicit

Dim swApp As Object
Dim longstatus As Long
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim swErrors As Long
Dim swWarnings As Long
Dim i As Long
Dim Assembly As ModelDoc2
Dim myAssy As AssemblyDoc
Dim myCmps As Variant
Dim myCmp As Component2

Sub main()
    Set swApp = Application.SldWorks
    Set Assembly = swApp.ActiveDoc
    Set myAssy = Assembly

    myCmps = myAssy.GetComponents(False)
    For i = 0 To UBound(myCmps)
        Set myCmp = myCmps(i)
        If (myCmp.GetSuppression = 3) Or (myCmp.GetSuppression = 2) Then
            bRet = myCmp.Select2(False, 0)
            Set swModel = myCmp.GetModelDoc2
            If swModel.GetType = swDocumentTypes_e.swDocPART Then
                swApp.ActivateDoc2 swModel.GetPathName, True, longstatus
                bRet = swModel.FeatureManager.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)
                'bRet = swModel.FeatureManager.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToTop, "", False)
                bRet = swModel.Save3(swSaveAsOptions_Silent, swErrors, swWarnings)
                swApp.CloseDoc (swModel.GetTitle())
            End If
            myAssy.EditAssembly
        End If
    Next i
    
    Assembly.ForceRebuild3 False
    Assembly.SaveAs (Assembly.GetPathName)
    
    MsgBox "Traitement terminé.", vbExclamation

End Sub

Kind regards

1 Like

Thank you all for your contributions, I select OBI WAN because there is also the macro to raise the block bar.

Thanks again :-) 

It's going well and you, despite the confinement that is starting to weigh on you....  

1 Like