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.
I have to tackle the track kindly proposed by @Cyril.fand 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.
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
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?):
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.
Because the macro of @m.bltworks 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.
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.
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.
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.
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...