2 Replies Latest reply on Dec 9, 2014 7:30 PM by Yong Ning

    How to get the feature name of Cut-Extrude?

    Yong Ning

      0.jpg

      How to obtain sketh name? | SOLIDWORKS Forums

      https://forum.solidworks.com/message/339500#339500

      ************************************************************************

      Sketch →

              Set SwFeat = .GetActiveSketch

              SwFeat.Select True

              Debug.Print SwFeat.Name

      ???

      Help me

      FeatureManager.FeatureCut → How to get feature name of Cut-Extrude1 name?

       

       

      ************************************************************************

       

       

      Private Sub ll()

        Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

           Set SwApp = Application.SldWorks

           Set SwModel = SwApp.ActiveDoc

        Dim SwSelMgr As SelectionMgr, Tmp

           Set SwSelMgr = SwModel.SelectionManager

       

        Dim SwAnn As Annotation, S As Sketch

           With SwModel

              Tmp = .Extension.SelectByID2("", "Face", 0, 0, 0, False, 0, Nothing, 0)

              .CreateCircleByRadius2 0, 0, 0, 0.025

              .FeatureManager.FeatureCut True, False, False, 1, 0, 0.01, 0.01, False, False, False, False, 0, 0, False, False, False, False, 0, 1, 1

           End With

      End Sub

        • Re: How to get the feature name of Cut-Extrude?
          Daniel Andersson

          Try:

           

          Private Sub ll()

               Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

               Set SwApp = Application.SldWorks

               Set SwModel = SwApp.ActiveDoc

               Dim SwSelMgr As SelectionMgr, Tmp

               Set SwSelMgr = SwModel.SelectionManager

               Dim SwAnn As Annotation, S As Sketch

               Dim swFeature as Sldworks.Feature

               Tmp = SwModel.Extension.SelectByID2("", "Face", 0, 0, 0, False, 0, Nothing, 0)

               SwModel.CreateCircleByRadius2 0, 0, 0, 0.025

               Set swFeature = SwModel.FeatureManager.FeatureCut3(True, False, False, 1, 0, 0.01, 0.01, False, False, False, False, 0, 0, False, False, False, False, 0, 1, 1, False, False, False, 0, 0, False)

               debug.print swFeature.Name

          End Sub

          FeatureCut is obsolete. Use FeatureCut3 that is available since SW2009 SP4. FeatureCut3 also returns a feature (IFeature interface).

            • Re: How to get the feature name of Cut-Extrude?
              Yong Ning

              Thanks your code.

               

               

               

               

              Function FeatureCutOfCircle(SwModel As ModelDoc2, ViewName, cutNameArr, R)

                Dim SwFeat As Feature, SketchFeat As Feature

                   With SwModel

                      Tmp = .Extension.SelectByID2(ViewName, "PLANE", 0, 0, 0, False, 0, Nothing, 0)

               

               

                      Tmp = .Extension.SelectByID2("", "Face", 0, 0, 0, False, 0, Nothing, 0)

                      For ii = 0 To UBound(cutNameArr)

                         .CreateCircleByRadius2 0, 0, 0, R / 1000

                         .ClearSelection2 True

                         Set SketchFeat = .GetActiveSketch

                         SketchFeat.Select True

                         SketchFeat.Name = cutNameArr(ii) & "_" & ii

                         Debug.Print SketchFeat.Name

                         Set SwFeat = .FeatureManager.FeatureCut(True, False, False, 1, 0, 1, 1, False, False, False, False, 0, 0, False, False, False, False, 0, 1, 1)

                         SwFeat.Name = cutNameArr(ii)

                         SwFeat.Select True

                        

                         .EditSuppress2

                        

                      Next ii

                    End With

              End Function

               

               

              Private Sub del()

                Dim Xls As Excel.Application

                   Set Xls = GetObject(, "Excel.Application")

                Dim Rng As Range, Arr()

                   Set Rng = Xls.Selection

                   nn = Rng.Rows.Count - 1

                ReDim Arr(nn)

                   For ii = 0 To nn

                      Arr(ii) = Rng(ii + 1, 1)

                   Next ii

                   ''

                Dim ViewName

                   ViewName = "前视基准面"

                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                   Set SwApp = Application.SldWorks

                   Set SwModel = SwApp.ActiveDoc

                  FeatureCutOfCircle SwModel, ViewName, Arr, 25

              End Sub