Delete features named something other than a number in textbox

I am trying to figure out how to loop a delete feature. I have a model template that I have 8 pre-built cut revolves. They are named "1 Step", "2 Step","3 Step","4 Step","5 Step","6 Step","7 Step" & "8 Step". I am trying to create a text box with the "instX" value be the the feature I want to KEEP. Loop though and delete the other 7 features and the absorbed sketches. I input 3 in my step count box it deletes 1,2,4,5,6,7 & 8 Step with the absorbed feature.

SolidworksApi macros
Answers 3
MS
MS 2018-03-22 Best Answer

Hello Mike,

Try this...

'STEP COUNT

Dim intX As Double

intX = cmbboxSTEPS.Value

Dim i As Integer

For i = 1 To 8

    If i <> intX Then

        swModel.Extension.SelectByID2 CStr(i) + " step", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0

        swModel.Extension.DeleteSelection2 (swDeleteSelectionOptions_e.swDelete_Absorbed)

    End If

Next i

MF
MF 2018-03-22

Thanks Michael, I'm not sure what this is doing.I certainly appreciate any help. I have just started learning VB. I took a solidworks API class but nothing like this was taught. I ordered a book and I'm hoping it will be here today.

     I am trying to get this to delete the numbers that Isn't selected in the box. For instance, I my stepcombbox value is 3, then it loops through and deletes the features called 1,2,4,5,6,7&8. leaving the feature 3. when I pasted this into my code its coming up with an error saying "compile error For without Next"

comment imagecomment image
MF
MF 2018-03-22

Sorry, Forgot the Next i portion of the code. Worked great!!