Delete multiple features, SelectSet

Delete multiple features, SelectSet

jcraig
Enthusiast Enthusiast
1,194 Views
2 Replies
Message 1 of 3

Delete multiple features, SelectSet

jcraig
Enthusiast
Enthusiast

I have a program where I have been deleting multiple features in a part document based on name. This program has been working it is just incredibly slow as the part regenerates after each feature deletion.

 

Here is the code that is being used for this.

    Public Sub DeleteSBCalFeatures()
        Dim sbDef As Inventor.PartComponentDefinition
        sbDef = Occ.Definition

        For Each feat As Inventor.PartFeature In sbDef.Features
            Try
                If feat.Name.Contains("SBCal-") Then
                    feat.Delete(False, False, False)
                End If
            Catch
            End Try
        Next

    End Sub

When you do this thru the user interface and select all of the features from the model tree the deletion process is much quicker than the program above.

 

I thought I would try using SelectSet to delete the features in one shot similarly to selecting them from the model tree.

 

The code below is what I tried. It just errors out without a good error message. It errors out at the selSet.Delete() line

 

    Public Sub DeleteSBCalFeaturesSs()
        Dim sbDef As Inventor.PartComponentDefinition
        sbDef = Occ.Definition
        Dim selSet As Inventor.SelectSet
        Dim sbDoc As Inventor.PartDocument
        sbDoc = sbDef.Document
        selSet = sbDoc.SelectSet
        selSet.Clear()

        For Each feat As Inventor.PartFeature In sbDef.Features
            Try
                If feat.Name.Contains("SBCal-") Then
                    selSet.Select(feat)
                End If
            Catch
            End Try
        Next

        selSet.Delete()

        selSet.Clear()
    End Sub

Do you have thoughts on how to make either the first process faster or make the SelectSet.Delete() function work?

 

Thanks

0 Likes
Accepted solutions (1)
1,195 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @jcraig.  There is a method right under the PartComponentDefinition called DeleteObjects , that lets you delete all objects in an ObjectCollection.  That would probably be quicker to use, but you would have to try it out to be sure.  Just loop through the features, checking their names, and if they pass the test, add them to an ObjectCollection that you made ahead of time.  Then pass that to that method after the loop to delete them all at once.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

jcraig
Enthusiast
Enthusiast

WCrihfield,

 

That method seems to do the trick. Much faster.

 

Thanks,

 

Jim

0 Likes