5 Replies Latest reply on Apr 20, 2017 3:59 AM by Peter Brinkhuis

    how can i extract feature data from feature manager using api?

    Shekhar Tanji

      i need to extract feature data automatically from feature manager pane to compare it with saved data from excel sheet database. how can i do it?

        • Re: how can i extract feature data from feature manager using api?
          Peter Brinkhuis

          What are you working with? Parts, assemblies, drawings? What kind of data do you need, the feature names or types? There are multiple examples in the help on feature tree traversal, you can check that out. If we have more info, we can give you some more info to get started.

          • Re: how can i extract feature data from feature manager using api?
            Shekhar Tanji

            Hi Peter I will try to be more specific now.

            I am working with parts. I am opening a neutral format part(.STEP format) and running recognize feature on it by right clicking imported1->FeatureWorks ->Recognize Features as shown below

            on completion i get following features

            Now what I all need is the number of features (in example above it is 5, Boss-Extrude1,Cut-Extrude1,Cut-Extrude2,M12 Clearance hole1,M13 clearance hole 1) so that i can store it in excel and do later operations on it.

             

            What I have implemented yet :

            Sub main()

            Dim swApp As SldWorks.SldWorks

                Dim myModel As SldWorks.ModelDoc2

                Dim featureMgr As SldWorks.FeatureManager

                Dim featArr As Variant

                Dim count As Long

             

                Set swApp = Application.SldWorks

                Set myModel = swApp.ActiveDoc

                Set featureMgr = myModel.FeatureManager

                count = featureMgr.GetFeatureCount(True)

             

                Set featArr = featureMgr.GetFeatures(True)    'getting type mismatch error here

                For i = 0 To count - 1

                    Set swFeat = featArr(i)

                    Debug.Print swFeat.Name  ' or fo any operation here

                Next i

             

            I am getting type mismatch at the highlighted line above featureMgr.GetFeatures(True) which returns array of all top level features.

             

            Questions :

            1. How to resolve type mismatch error(is there any specific array type Solidworks provides)?

            2. Even if i traverse through array how can i select only particular features?, because the feature names are dynamic.

            3. Or is there any function to find if the substring exist in a string so that i can search for Boss-Extrude,Cut-Extrude(which are same for all parts) in the traversed array and retrieve only those?

             

            PS : I am also aware of Set rootNode = featureMgr.GetFeatureTreeRootItem() method.

             

            I am amateur in macro programming, kindly help me out.

              • Re: how can i extract feature data from feature manager using api?
                Peter Brinkhuis

                The way to resolve the type mismatch is to remove the set command. Set is only required for objects and variant isn't an object per se. It can contain objects though. To prevent issues further down the line, you should consider starting the file with the line Option Explicit so it will give an error when not all variables are defined. In this case i and swFeat weren't defined. You can also turn the option on in the settings by enabling "Require Variable Declarations".

                 

                If you're only interested in the feature count, there is a command for that in the feature manager: GetFeatureCount.

                 

                When traversing the tree, you can use swFeat.GetTypeName2 to get the type of the feature. That will give you a language-independent and user-input-independent feature name.