Maccro Assembly Promotion

Hello

I'm looking for a maccro to promote all the subassemblies of an open assembly.
After that, the little extra would be to promote all the subassemblies except one in which the title still includes "VER".
But already with a maccro who would do the 1st action explained, it would be great!
I link  a maccro found elsewhere that is close to it.

Kind regards


ficap_macro_promouvoir.swp

You need to create an additional loop to go through the components:

Look at this code proposed by @Cyril.f  in this link:

https://www.lynkoa.com/forum/autres-produits/macro-s%C3%A9lectionner-un-composant-dans-un-assemblage?page=0#answer-

Then you add the part where you filter the assembly see the filter to ignore according to the name and you add the code to promote the assembly.

 

 

 

2 Likes

I understand the process to be carried out but not being a programmer I am not able to modify this maccro.

I have to tackle the track kindly proposed by @Cyril.f and relayed by @sbadenis , so if I get out of it I should be able to make you this one by the way.

On the other hand I don't know what it means to promote here, so I'm not sure I can test it properly.

2 Likes

Promote is for the nomenclatures and it happens at the level of the nomenclatures:

https://help.solidworks.com/2021/french/WhatsNew/c_wn2021_pdm_bom_options.htm

2 Likes

Here is my macro:

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

Without modifying the code you can run a macro on all your assemblies  or an assembly and all the subassemblies via Integration of the MyCad utility (1-month trial period: https://www.lynkoa.com/mycadtools) or otherwise via batch + (free?):

https://cadplus.xarial.com/batch/assembly/

Thank you for your feedback, the idea was to have a tool that can be used by the team for today as well as for 2 years or +.
 

Hello

The macro attachment combines the codes from the various messages above. It seems to me to respond to your initial request.
As always: to be tested and validated before using without moderation.

Kind regards.


promotionmep.zip
2 Likes

After testing I had an error when running the maccro.
Attached is the screenshot of this error.

 


bug_maccro.png

Did you start the procedure by hand?

Because the macro of @m.blt works very well at home.

To start the main procedure, either by editing the macro, you put your mouse cursor after Sub main()  at the very end of the macro, and you click on f5.

Either in tool run and then macro path.

If still in error perhaps send a simplified and unprotected assembly via project manager to test it.

1 Like

To launch the maccro, I opened a test assembly (no subassembly, only parts) then Tool => Maccro => I point to the maccro on my desktop and Run.
Then I got the error message several times that I posted in image above.
I just tested again (after restarting the PC) and it's very strange.

The maccro launched, no bug alert, the maccro interface disappeared, no error message.
But when I went to check in the configurations of the assemblies none of them had the promotion enabled.
In conclusion, it seems that nothing happened.

I use a maccro that automatically creates PDFs of several plans and it works wonderfully.
So I don't know why this maccro has no effect or bug.

As said @sbadenis you have to choose the Main procedure from "macro path" and then validate.

Same if you add the button to a toolbar, you have to edit the button and choose the Main procedure.

1 Like

Hello @Psyno,

Your screenshot identifies the location of the error, but to be complete and effective, you should attach the message of this error, as it is sent back by VBA. Suspicious lines:

vChildComp = swComp.GetChildren
    For i = 0 TB UBound(vChildComp)
        Set swChildComp = vChildComp(i)
        If (swChildComp.GetSuppression2 = swComponentResolved) Or (swChildComp.GetSuppression2 = swComponentFullyResolved) Then

The last line verifies that the child component being processed is not in the "Deleted" state, so it is in the "Resolved" state.
I don't see what can generate an error...

There are two possible causes:
- The swChildComp component is non-existent (Nothing) or of an unsuitable type. You can place a spy who will give his name (swChildComp.Name2) to find out more...
- The constants  swComponentResolved and swComponentFullyResolved are unknown on your PC. They are worth 3 and 2 respectively.
To put it simply, you can test by replacing them with these values.
To be more rigorous, we need to make these constants accessible in the code, as well as all the other constants in the SolidWorks APIs.
They are defined in the "SolidWorks 2021 constant type Library" add-in.
Just add it to the VBA references (Tools > References, and check the appropriate box). Make sure you have the references to SolidWorks visible in the attached image.

 

1 Like

Small precision, I'm on SolidWorks 2018 (I don't know if it changes anything).
Concerning the checkbox, attached are the references of my maccro.

To answer Sylk, I don't know what you're talking about.
When I launch the maccro I target it via the SW explorer and I point to the PromotionMEP.swp file .
I don't know how else to point out before I execute it.


screenshot.png

The pleasure of successive versions of SolidWorks...

The GetSuppression2 function does not exist in the 2018 version.
It should be replaced by GetSuppression (so just delete the 2!).
And it should start working.

One more note: it seems to me that the Promote (or Hide or Show) option of a drawing only makes sense for an assembly. The macro therefore concerns a main assembly that contains subassemblies whose components we want to see or not in the MEP nomenclature.
An assembly that contains only parts is not taken into account...

3 Likes

Indeed, after editing the GetSuppression2 lines , the maccro works very well!
Thank you all!