2 Replies Latest reply on Jul 7, 2016 12:16 PM by Adam Hoffman

    How to get count of Sketches in the PartFile

    Suresh Vijayan

      Here Im A having a part file Which Consists of sketches i need to get that count of sketches in in the part file.

       

      Kindly Guide to get the solution.

      Image1.PNG

      Here see there are Two sketches in the part file how i can get that count programmatically.

       

      Thanks & Regards

      Suresh

        • Re: How to get count of Sketches in the PartFile
          Amen Allah Jlili

          Hello


          Maybe this could help you.


          Use the IGetFeatures method to get all features. Use false as parameter to make sure all features at sub-levels are be accounted for.
          Reference 2012 SOLIDWORKS API Help - GetFeatures Method (IFeatureManager)

          Traverse the features array and check the type of each feature using this method GetTypeName2. Sketch features are named "ProfileFeature".
          2010 SOLIDWORKS API Help - GetTypeName2 Method (IFeature)

          • Re: How to get count of Sketches in the PartFile
            Adam Hoffman

            Dim swApp           As SldWorks.SldWorks

            Dim swModel         As SldWorks.ModelDoc2

            Dim swFeat          As SldWorks.Feature

            Dim iCount          As Integer

             

            Sub main()

             

            Set swApp = _

            Application.SldWorks

             

            If swApp.GetDocumentCount() = 0 Then Exit Sub

             

            Set swModel = swApp.ActiveDoc

             

            If swModel.GetType() = swDocumentTypes_e.swDocDRAWING Then Exit Sub

             

            iCount = 0

             

            Set swFeat = swModel.FirstFeature

             

            Do While Not swFeat Is Nothing

             

               If swFeat.GetTypeName2() = "3DProfileFeature" _

                  Or swFeat.GetTypeName2() = "3DSplineCurve" _

                  Or swFeat.GetTypeName2() = "CompositeCurve" _

                  Or swFeat.GetTypeName2() = "LayoutProfileFeature" _

                  Or swFeat.GetTypeName2() = "PLine" _

                  Or swFeat.GetTypeName2() = "ProfileFeature" _

                  Or swFeat.GetTypeName2() = "RefCurve" _

                  Or swFeat.GetTypeName2() = "RefPoint" _

                  Or swFeat.GetTypeName2() = "SketchBlockDef" _

                  Or swFeat.GetTypeName2() = "SketchHole" _

                  Or swFeat.GetTypeName2() = "SketchPattern" _

                  Or swFeat.GetTypeName2() = "SketchBitmap" Then

                 

                  iCount = iCount + 1

                 

               End If

              

               Set swFeat = swFeat.GetNextFeature

             

            Loop

             

            MsgBox ("The Number Of Sketch Features Is: " + CStr(iCount))

             

            End Sub