11 Replies Latest reply on May 4, 2018 11:55 AM by Mike Flanders

    delete a feature with a text box "yes or no" ??

    Mike Flanders

      Hey guys, I have a question on how to have a text box that says "Yes" or "no" to delete or not delete a feature in my template? if yes it leaves the feature and if no it deletes the feature.  I recorded the code but I don't know how to get it to interact with the text box in my macro. Anyone want to take a look at this?

       

      SHANK NIB YES NO.JPG

        • Re: delete a feature with a text box "yes or no" ??
          Jacob Corder

          Looks like you are making cavity form tools there.

           

          To delete the feature. Check if combobox is yes then

          Programmatically select the feature and call

           

          2018 SOLIDWORKS API Help - Delete Selected Feature Example (VBA)

            • Re: delete a feature with a text box "yes or no" ??
              Mike Flanders

              We are a carbide company that processes carbide from powder and machine these parts in a state like chalk then they are sintered in a furnace. We make any style cutter you could imagine.

              • Re: delete a feature with a text box "yes or no" ??
                Mike Flanders

                I don't understand how to get it to look at the combobox  to run the code or not to run the code. 

                  • Re: delete a feature with a text box "yes or no" ??
                    Jacob Corder

                    I love carbide manufacturing.  So cool. Especially the through coolant holes in drills.  Spirals..  magic. We use form tools for hydraulic manifolds.

                     

                    Features cannot look at controls.  You must execute the code behind the control.  So when creation of your part is executed you must look at the combobox to determine if you delete the feature or not.

                     

                    Think if your code as a person. The feature cannot read your mind. It must be commanded to do something.

                      • Re: delete a feature with a text box "yes or no" ??
                        Mike Flanders

                        This is a model creator. I have it built with the worse case scenario part with spiral flutes, coolant and also Straight flutes and  Coolant. Basically this macro is a form that I am building that dumbs down my part template. Someone that isn't a solidworks junky like myself can get in here and create basic cutting tools with just a form. In any case in that macro, the features are already built and named something it can look for. My thought is It kind of needs to do an If-Then statement code were if the box is checked, do this. If not do this. I'll keep researching it. I know it can be done. In the API world (which i'm just learning) I would think this would be an easier function to execute. Maybe not?

                        • Re: delete a feature with a text box "yes or no" ??
                          Mike Flanders

                          What company you work for Jacob? Good chance we make the carbide your form cutters are made from.

                            • Re: delete a feature with a text box "yes or no" ??
                              Jacob Corder

                              JEM Technical in Minnesota

                               

                              here is your check

                               

                              If UCase(CmbBoxSHANK.value) = "YES" Then

                              'Shank Diameter

                                  If Val(shankdiametertxtbox.Text) <> 0 Then

                                      boolstatus = swModel.Extension.SelectByID2("Shank Ø@Shank Sketch", "DIMENSION", -0.155119488290314, 8.15696945460451E-03, 4.48889141565494E-02, False, 0, Nothing, 0)

                                      Set myDimension = swModel.Parameter("Shank Ø@Shank Sketch")

                                      myDimension.SystemValue = (shankdiametertxtbox.Text) * 0.0254

                                      End If

                                

                                      'Shank Length

                                      If Val(shanklengthtxtbox.Text) <> 0 Then

                                      boolstatus = swModel.Extension.SelectByID2("Shank Length@Shank Sketch", "DIMENSION", -0.155119488290314, 8.15696945460451E-03, 4.48889141565494E-02, False, 0, Nothing, 0)

                                      Set myDimension = swModel.Parameter("Shank Length@Shank Sketch")

                                      myDimension.SystemValue = (shanklengthtxtbox.Text) * 0.0254

                                  End If

                              Else

                                  Dim ShankFeat As Feature

                                  Set ShankFeat = swpart.FeatureByName("SHANK")

                                  If Not ShankFeat Is Nothing Then

                                      ShankFeat.Select2 True, -1

                                      Dim ShankSketch As Feature

                                      Set ShankSketch = swpart.FeatureByName("SHANK SKETCH")

                                      ShankSketch.Select2 True, -1

                                      swModel.DeleteSelection False

                                  End If

                              End If

                               

                               

                               

                               

                              also in straightFlute you never instantiated ISwapp

                               

                              Sub StraightFlute()

                               

                               

                              'MsgBox "DeleteStraightFlutefeatures"

                              Set swApp = Application.SldWorks

                               

                               

                              your loop is wrong for deleting the steps

                               

                              'STEP COUNT

                              Dim intX As Double

                              intX = cmbboxSTEPS.value

                              Dim i As Integer

                              For i = intX To 8

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

                                      swModel.Extension.DeleteSelection2 (swDeleteSelectionOptions_e.swDelete_Absorbed)

                                Next i

                                • Re: delete a feature with a text box "yes or no" ??
                                  Mike Flanders

                                  I didn't like the box popping up so I turned it into a comment and it still worked. I have been messing around with this and don't  really know what I'm doing. I took an API class through solidworks but it was just the beginning to my understanding of this. I purchased a book but i'm only on chapter two. lol. I do appreciate all the support I have been getting on this forum. I will copy some of this in there and see if I can get it working. My next class I Driveworks so I will probably be doing this all over again. The key is the solid model being built with independent features. I think I have it pretty sound.