Removing Components from an Assembly via vba

Hi all

I am coming to you hoping to find help.

Context:

I would like to control solidworks assemblies from excel using macros. Basically, excel opens assemblies one after the other, deleting or resolving components in them.

My problem lies in the command to remove these components: I tried to open the part family (via my macros) and modify it but it doesn't work and ends up corrupting the part family. In addition, it creates a lot of errors when the part family is opened at the same time as another excel file.

Possible resolution:

So I found the EditSuppress2() function, but I can't adapt it to my code. If anyone knows this function well and can guide me, I'll give you my piece of code.

Code:

 

Private Sub CommandButton1_Click()

Dim swApp As Object

Dim Model As ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim ret As Boolean

Set swApp = CreateObject("SldWorks.application")

Set Model = swApp.ActiveDoc
Set swModelDocExt = Model.Extension
 
boolstatus = swModelDocExt.SelectByID2("Gear Pump<1>", "swSelCOMPONENT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Model.EditSuppress2()

ret = swModelDocExt.Rebuild(swRebuildOptions_e.swRebuildAll)


End Sub

 

I thought I saw miracles working here;) I hope to find help.

Have a nice day

Take a look at this method instead:
http://help.solidworks.com/2017/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IComponent2~SetSuppression2.html

Thanks for the answer, I didn't know this function, I'll try it.

Thank you Thomas for this function, there must surely be a way to solve the problem thanks to it but I found the solution thanks to EditSuppress2().

I'll give you my code for those who are interested.

(The EditUnsuppress2() function does the opposite of EditSuppress2(), it resolves the component.)

Code:

Private Sub CommandButton1_Click()

Dim swApp As Object

Dim Model As ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim ret As Boolean

Set swApp = CreateObject("SldWorks.application")

Set Model = swApp.ActiveDoc
Set swModelDocExt = Model.Extension
 
boolstatus = swModelDocExt.SelectByID2("Part1-1@Assemblage1", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Model.EditSuppress2()
'boolstatus = Model.EditUnsuppress2()

ret = swModelDocExt.Rebuild(swRebuildOptions_e.swRebuildAll)


End Sub