MACRO act only on one option choice

Good morning everyone,

I made a small macro to exclude all the selected parts from the nomenclature. (via Record Mode)

The only problem is that the macro acts on all the other options in the same group (group5 in red below). 


 

Here's the code (if I remember correctly I had to delete a line with a part name)

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.CompConfigProperties5(2, 0, True, True, "Défaut<Brut d'usinage>", True, False)
boolstatus = Part.EditRebuild3()
End Sub

 

API Link: CompConfigProperties5

Note: The last 2 are reversed from the window. (exclude from BOM and envelope)

This makes exclude nomenclature the penultimate variable.

 

So question: can we only act on exclude from the nomenclature??

 

Thanks in advance

Hello 

So you want to select parts and run the macro so that those parts are excluded from the BOM? 

"So question: can we only act on exclude from the nomenclature?? "

-> Want to know if you can change the properties of the component without changing the other settings?

If this is the case, I propose the following modification, which retrieves the information of the selected entity and adds this information to the CompConfigProperties function in order to modify only the exclusion of the nomenclature.

It's up to you to see if it works the way you want it to.

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swEntity As SldWorks.Entity
Dim swComponent As SldWorks.Component2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelectionMgr = swModel.SelectionManager
Set swEntity = swSelectionMgr.GetSelectedObject6(1, -1)

Set swComponent = swEntity.GetComponent


boolstatus = swModel.CompConfigProperties5(swComponent.GetSuppression, swComponent.Solving, swComponent.Visible, True, swComponent.ReferencedConfiguration, True, swComponent.IsEnvelope)
boolstatus = swModel.EditRebuild3()


End Sub

 

Gauthik

Hello

It is also possible to use the http://help.solidworks.com/2017/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.icomponent2~excludefrombom.html?verRedirect=1 function which acts directly on the "Exclude from BOM" checkmark.

Kind regards

ok thank you 2.

Logically the 2nd solution would be the right one to see how to use it in the macro as it should be. Even if the 1st is another viable solution.

Let's say that my current macro works since 90% of my parts are designed the same way.

But in case for the parts where I put several configurations, it changes me in my assembly these parts in the 1st configuration (default) and suddenly breaks the assembly (just re-select the right configuration).

Otherwise, the other solution is to select the rows to be excluded from the nomenclature table.

I'll test it as soon as possible

Thank you again for these 1st answers

You can also try a program that I made available in the tutorials, it's HERE, it's written in C# but it's also doable in VBA and I use the "ExcludeFromBOM" function in it.

Kind regards