Operate the Macro Block Bar on All Parts of an Assembly

Hi all

Does anyone know of a macro to operate the freeze bar on all parts of an assembly (see all parts of different subassemblies if possible)?

I look but can't find it...

Thank you!

I found this macro that doesn't always work, but didn't have time to dig deeper:

'       MODULE:         FREEZE PARTS

'       PROGRAMMER:     DMITRY ZAMOSHNIKOV

'       DATE:           11/13/2013

'       PURPOSE:

'           GO THROUGH AN ASSEMBLY AND FREEZE EVERY PART IN THE ASSEMBLY.

'       FUNCTION: FREEZE_ALL

'           IN: NONE

'           OUT: ALL PARTS==FROZEN?

'

 

 

Dim swdoc As SldWorks.ModelDoc2

Dim swAllDocs As EnumDocuments2

Dim FirstDoc As SldWorks.ModelDoc2

Dim boolstatus As Boolean

Dim NumDocsReturned As Long

Dim DocCount As Long

Dim swapp As SldWorks.SldWorks

Dim longstatus As Long

Dim part As Object

 

 

'   FREEZE_ALL

'       WHILE (PARTS IN ASSEMBLY NOT FROZEN > 0 )

'           OPEN PART

'           FREEZE PART

'           SAVE PART

'           CLOSE PART

'       WEND

Public Sub FREEZE_ALL()

    Set swapp = Application.SldWorks

    Set swAllDocs = swapp.EnumDocuments2

    Set FirstDoc = swapp.ActiveDoc

 

    DocCount = 0

    swAllDocs.Reset

    swAllDocs.Next 1, swdoc, NumDocsReturned

 

 

    ' This loop will go through all of the documents within an assembly, including sub-assemblies.

    While NumDocsReturned <> 0

            bDocWasVisible = swdoc.Visible ' Use Hidden Parts

 

            ' script crashed if an attempt to freeze an assembly is made.

            ' check the file to make sure it's a "sldprt" file.

            If (UCase(Right(swdoc.GetPathName, 6)) = UCase("sldprt")) Then

                swapp.ActivateDoc2 swdoc.GetPathName, True, longstatus 'open and activate the part

                boolstatus = swdoc.FeatureManager.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", True)    ' move the freeze bar to the end

                swdoc.SaveAs (swdoc.GetPathName)    ' save the change

                swapp.CloseDoc (swdoc.GetTitle())   ' close the part

            End If

 

            swAllDocs.Next 1, swdoc, NumDocsReturned   ' Go to the next part

            DocCount = DocCount + 1    ' Keep a count of all parts within the assembly, including sub-assemblies.

    Wend

 

 

End Sub

 

 

Sub FREEZE_ONE()

 

    Set swapp = Application.SldWorks

 

    Set part = swapp.ActiveDoc

    boolstatus = part.FeatureManager.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", True)

 

    part.SaveAs (part.GetPathName)

    'swapp.CloseDoc part.GetTitle()

 

 

End Sub

The original link:

https://forum.solidworks.com/thread/74956

Hello

Or the "Integration" tool in myCADtools

https://help.visiativ.com/mycadtools/2021/fr/Integration114.html 

Cdlt

Alan

Thank you for your feedback.

@sbadenis, I had found this macro as well, but it doesn't work (except individually on the part directly, which is not very useful...)

@acombier, unfortunately, I don't have mycadtools. We are still in SW2016 SP05 without support.... (No comment).

I just re-tested it on an assembly and it seems to work.

Are you launching the freezeALL sub?

If you launch the freeze one it works only on the current part.

Basically, you have to run the macro (?):

' MODULE: FREEZE PARTS ' PROGRAMMER: DMITRY ZAMOSHNIKOV ' DATE: 11/13/2013 ' PURPOSE: ' GO THROUGH AN ASSEMBLY AND FREEZE EVERY PART IN THE ASSEMBLY. ' FUNCTION: FREEZE_ALL ' IN: NONE ' OUT: ALL PARTS==FROZEN? ' Dim swdoc As SldWorks.ModelDoc2 Dim swAllDocs As EnumDocuments2 Dim FirstDoc As SldWorks.ModelDoc2 Dim boolstatus As Boolean Dim NumDocsReturned As Long Dim DocCount As Long Dim swapp As SldWorks.SldWorks Dim longstatus As Long Dim part As Object ' FREEZE_ALL ' WHILE (PARTS IN ASSEMBLY NOT FROZEN > 0 ) ' OPEN PART ' FREEZE PART ' SAVE PART ' CLOSE PART ' WEND Public Sub FREEZE_ALL() Set swapp = Application.SldWorks Set swAllDocs = swapp. EnumDocuments2 Set FirstDoc = swapp. ActiveDoc DocCount = 0 swAllDocs.Reset swAllDocs.Next 1, swdoc, NumDocsReturned ' This loop will go through all of the documents within an assembly, including sub-assemblies. While NumDocsReturned <> 0 bDocWasVisible = swdoc. Visible ' Use Hidden Parts ' script crashed if an attempt to freeze an assembly is made. ' check the file to make sure it's a "sldprt" file. If (UCase(Right(swdoc. GetPathName, 6)) = UCase("sldprt")) Then swapp. ActivateDoc2 swdoc. GetPathName, True, longstatus 'open and activate the part boolstatus = swdoc. FeatureManager.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", True) ' move the freeze bar to the end swdoc. SaveAs (swdoc. GetPathName) ' save the change swapp. CloseDoc (swdoc. GetTitle()) ' close the part End If swAllDocs.Next 1, swdoc, NumDocsReturned ' Go to the next part DocCount = DocCount + 1 ' Keep a count of all parts within the assembly, including sub-assemblies. Wend End Sub

Hello

In my humble opinion, you shouldn't launch anything at all without first reading and analyzing the operation of this macro which doesn't work very well but downright too well ...

The "EnumDocuments2" function is a high-level function in the Sldworks namespace, it allows you to know all the documents open in Solidworks and not only in the assembly that you think you are processing...

Kind regards

1 Like

Hello

That's a gift.

May the force be with you.

 


freeze.zip
3 Likes

@OBI WAN, this seems much more coherent to me ...

 

1 Like

At the top OBIWAN! Thank you all for your answers.

1 Like