Enable the PROMOTE via macro option

To follow up on the question: http://www.lynkoa.com/forum/3d/famille-de-piece-promouvoir

I don't master MACROS, someone could make me a macro to activate the Promote option in all configurations of a room.

Thank you in advance.


2015-02-06-famille_de_piece_-_promouvoir.jpg

Hello

Rereading the two pieces of code I posted in the previous question, it's easier than I thought, but I didn't have time to test.

To be put in a new macro in SolidWorks from the " Macro > New Tools > Tools " menu.

'Edit: code cleanup and comments

Option Explicit
Sub main()
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim vConfNameArr            as Variant
    Dim sConfigName             As String
    Sun i                       As Long

   
    Set swApp = CreateObject("SldWorks.Application")
        SolidWorks Enables in VBA
    Set swModel = swApp.ActiveDoc
       'Retrieves the active document
    vConfNameArr = swModel.GetConfigurationNames
       'Retrieves all configurations in an array
    For i = 0 To UBound(vConfNameArr)
       Loop across all configurations
        sConfigName = vConfNameArr(i)
       sConfigName.ChildComponentDisplayInBOM = swChildComponentInBOMOption_e.swChildComponent_Promote
       'Activates the promote function on each of the configurations
    Next i
End Sub

 

2 Likes

A priori there is an error (see attached file)


2015-02-06-macro_-_promouvoir.jpg

There cannot be 2 hands in the same program and there was an autocorrect error with apostrophes.

 

The code should be like on the PDF of this tutorial that I just put online:

http://www.lynkoa.com/tutos/solidworks/macro-pour-toutes-les-configurations-d-un-assemblage-pour-activer-l-option-%E2%80%9Cpromouv

 

And I updated the code above, it should work.

 

I ran the corrected macro but it gives me a new error message

(see attachment).

 


2015-02-09-erreur_macro_promouvoir.png

I'm trying to test the macro tonight.

I have a colleague who knows macros, here's what he wrote.

After a test or two, it seems to work.

 

Option Explicit
Sub main()
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swConfig                As SldWorks.Configuration
    Dim vConfNameArr            as Variant
    Dim sConfigName             As String
    Sun i                       As Long

  
    Set swApp = Application.SldWorks
        SolidWorks Enables in VBA
    Set swModel = swApp.ActiveDoc
       'Retrieves the active document
    vConfNameArr = swModel.GetConfigurationNames
       'Retrieves all configurations in an array
    For i = 0 To UBound(vConfNameArr)
       Loop across all configurations
        Set swConfig = swModel.GetConfigurationByName(vConfNameArr(i))
        'sConfigName = vConfNameArr(i)
        swConfig.ChildComponentDisplayInBOM = swChildComponentInBOMOption_e.swChildComponent_Promote
       'Activates the promote function on each of the configurations
      
    Next i
End Sub


ficap_macro_promouvoir.swp

The macro attachment works.


ficap_macro_promouvoir.swp