"Some of the selected entities cannot be deleted" popup

Hello All

I have a macro to delete suppressed features. It mostly works very well but occasionally I get the popup which requires a user click.

What I find confusing is that for the same test files, sometimes it appears and sometimes not.


Is there a way to force Solidworks to be silent during this operation?

Otherwise I presume it is something to do with the order the features are deleted.

For convenience I am using MultiSelect2 and DeleteSelection2

In the docs it says this method doesn’t ask the user to confirm deletion, but it still pops up this dialog. grrr!

I think I’ve added the features to the array in reverse tree order as in my mind I thought this may help but I suppose it depends on the tree dependencies.
I messed around with the options and it worked great until it didn’t lol

BTW All the features ARE deleted. It does leave behind some empty folders which I was going to deal with next

Thanks in advance for any guidance.

code follows

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks

    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then Exit Sub
    Dim swFeatureManager As SldWorks.FeatureManager
    Set swFeatureManager = swModel.FeatureManager
    Dim swFeature As SldWorks.Feature
    Set swFeature = swModel.FirstFeature
    Dim SelectionCollection As New Collection
        If swFeature.IsSuppressed2(swInConfigurationOpts_e.swAllConfiguration, Nothing)(0) Then
            SelectionCollection.Add swFeature
        End If
        Set swFeature = swFeature.GetNextFeature
    Loop While Not swFeature Is Nothing
    If SelectionCollection.Count > 0 Then
        ReDim SelectionArray(SelectionCollection.Count) As SldWorks.Feature
        Dim i As Long
        For i = SelectionCollection.Count To 1 Step -1
            Set SelectionArray(i - 1) = SelectionCollection(i)
        Next i
        Set SelectionCollection = Nothing
        swModel.Extension.MultiSelect2 SelectionArray, False, Nothing
        swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed + swDeleteSelectionOptions_e.swDelete_Children + swDeleteSelectionOptions_e.swDelete_Advanced
        DeleteBrokenEquations swModel
    End If
End Sub

Private Function DeleteBrokenEquations(swModel As SldWorks.ModelDoc2) As Boolean
    Dim DeletionOccured As Boolean
    Dim swEquationManager As SldWorks.EquationMgr
    Set swEquationManager = swModel.GetEquationMgr()
    Dim i As Long
    For i = swEquationManager.GetCount - 1 To 0 Step -1
        If IsEquationBroken(swEquationManager, i) Then
            swEquationManager.Delete i
            DeletionOccured = True
        End If
    DeleteBrokenEquations = DeletionOccured
End Function

Function IsEquationBroken(swEquationManager As SldWorks.EquationMgr, i As Long) As Boolean
    Dim value As String
    value = swEquationManager.value(i)
    Debug.Print value
    IsEquationBroken = (swEquationManager.Status = -1)
End Function

Maybe you are trying to delete features that have already been deleted. That’s one of the dangers of editing a list while going through that same list.

1 Like

So deleting one at a time in reverse order gets us there - but is very slow in comparison.

I’ll have turn off the tree/ graphics update

    If SelectionCollection.Count > 0 Then
        Dim i As Long
        For i = SelectionCollection.Count To 1 Step -1
            Set swFeature = SelectionCollection(i)
            swFeature.Select2 False, -1
            swModel.Extension.DeleteSelection2 0
        Next i
        DeleteBrokenEquations swModel
    End If

Deleting is a slow action because it triggers a rebuild. But why delete features one by one when you already have a collection of items to be deleted? Just select them all and call DeleteSelection2.

Even going through the feature tree in reverse may cause trouble because a child can have multiple parents and vice versa. But if you only select and delete suppressed features, it may just work.

1 Like

Thanks Peter

That was my first code but it caused the pop up.

I’ve sent a ticket into my VAR about it for what good it will do lol

I’ve disabled the view and tree and the speed is alright.

I use this as part of my configuration ripping process so I’d prefer a bit slower but with no pops up so I can do something else. Like have a coffee and a smoke lol

You can definitely suppress some dialogbox messages in SOLIDWORKS by using the “/r/b” arguments when launching sldworks.exe process. I’m not too sure that particular messagebox is affected by it.

Are there any check you can perform to see if the feature can be delete prior to deleting them?

1 Like

Hey Amen

Thankyou - That’s good info to know.

I ended up deleting the features one at a time in reverse tree order and that worked a treat.

I also spoke to my VAR and he said he would raise an ER to the affect that we should be able to block pop ups.

1 Like

Yeah. It could also be that you are deleting features using a loop (for i or for each) and those features depend on each other so by deleting one, you are deleting others in the array causing that error message.

Yeah - notice there’s no way, no combination of options to delete without this problem. It exists in Solidworks 2018 when I’m using it manually. That’s why this macro solution is better.

The other pop up I hate is the one you get when you select a driven dimension… yeah I know its driven… duh!

but thats a different story