5 Replies Latest reply on Jul 29, 2017 11:05 PM by Nilesh Patel

    FeatureExtrusion3 fails when added in loops

    Rahul Khande



      I'm extruding my sketch in loops for example 4.
      But after first iteration i.e. after extruding sketch at index 1, FeatureExtrusion3 fails.
      Also I found that after FeatureExtrusion3 for 2nd iteration, my sketch gets disturbed.

      Below is the code I used for extrusion.
      swModelDocExt.SelectByID2("Sketch" + SketchIndex, "SKETCH", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault); // sketch index increments as per loops. initialized to 1 at start


      Feature feature = swFeatureManager.FeatureExtrusion3(true,false,false,(int)swEndConditions_e.swEndCondThroughAll,

                      (int)swEndConditions_e.swEndCondThroughAll,height * SWGlobalRenderer.InchtoCmMultiplier,height * SWGlobalRenderer.InchtoCmMultiplier,false,false,









      Here is the snapshot of sketch:
      Actually, I confirmed that my sketch profile is perfect as expected but it gets disturbed after extrusion of sketch1 as shown in image below.




        • Re: FeatureExtrusion3 fails when added in loops
          Nilesh Patel

          Hi Rahul,


          I have created a macro from your codes and works fine for me. Below are the codes.


          Option Explicit
          Sub main()
              Dim swApp           As SldWorks.SldWorks
              Dim swModel         As SldWorks.ModelDoc2
              Dim swFeatMgr       As SldWorks.FeatureManager
              Dim swFeat          As SldWorks.Feature
              Dim i               As Integer
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swFeatMgr = swModel.FeatureManager
              For i = 1 To 4
                  swModel.Extension.SelectByID2 "Sketch" & i, "SKETCH", 0, 0, 0, True, 0, Nothing, 0
                  Set swFeat = swFeatMgr.FeatureExtrusion3(True, False, True, swEndConditions_e.swEndCondThroughAll, swEndConditions_e.swEndCondThroughAll, 0, 0, _
                                                           False, False, False, False, 0, 0, False, False, False, False, True, True, False, _
                                                           swStartConditions_e.swStartSketchPlane, 0, False)
              Next i
              swModel.ClearSelection2 True
          End Sub


          Here are before the macro and after the macro screenshots.

          Before the macro:


          After the macro:


          I guess you are using SW2016 or SW2017 whereas I am still using SW2015, so even if you attach your part here, I won'e be able to open it.


          Good luck.



            • Re: FeatureExtrusion3 fails when added in loops
              Rahul Khande

              Thank you Nilesh.
              Your suggestion worked for me in scenario explained below:

              1. Create a sketch for e.g. Sketch1.
              2. Start the iteration.
              3. Select "Sketch1" and extrude
              4. Continue extrude on "Sketch1" for required number of extrude iterations.




              Now, I have a different sketch, in each iteration, new sketch is created at different location in same part file.

              My new scenario is
              1. Start the iteration.
              2. Create a sketch for e.g. Sketch1 or Sketch at index.
              3. Select respective Sketch for e.g. for iteration 1 select "Sketch1" and extrude

              4. Extrude on "Sketch1".

              5. Start next iteration
              In my above explained scenario, extrusion fails.


              Can you please check for above second scenario.

                • Re: FeatureExtrusion3 fails when added in loops
                  Nilesh Patel

                  Hi Rahul,


                  Code I posted doesn't create 4 extrusions for same sketch (e.g. Sketch1) but it selects Sketch1 and creates extrusion for Sketch1. Then selects Sketch2 and creates extrusion for Sketch2. Runs this loop for all 4 sketches in my model. This the scenario you are looking for.

                    • Re: FeatureExtrusion3 fails when added in loops
                      Rahul Khande

                      Thank you Nilesh.


                      I could reproduce the issue in new template project:
                      Attached is my code :

                      Please follow the steps below:


                          1. Unzip the attached zip file.


                          2. Launch the project in Visual Studio 2012.


                          3. Run the application i.e. SolidWorks will run.


                          4. Click on C# Plugin tab => "Create Cube"


                          5. Check the output.


                      In case you are not able to build, I have attached a text file containing my functions:


                      Start point of execution is : CreateCube()


                      Please review the same and share your suggestions.

                        • Re: FeatureExtrusion3 fails when added in loops
                          Nilesh Patel

                          Hi Rahul,


                          I ran your codes.

                          1. You create a sketch and then extrude the same sketch.

                          2. You then move the body to a location (X= 0.8593, Y= 0.4063).

                          3. You repeat these steps 5 times (creating a sketch at same location and same shape and moving the body at same location).


                          I ended up with 5 extruded bodies (all same in size and shape) and moved to same location which looked like one body. I didn't run into any trouble. But this doesn't tell me what is your problem or what you would like to achieve. I am sure you don't want to create 5 identical bodies moved to a same location.


                          Could you explain more about what is your end goal is?