-
Re: how can i extract feature data from feature manager using api?
Peter Brinkhuis Apr 15, 2017 8:09 AM (in response to Shekhar Tanji)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 Apr 16, 2017 3:10 AM (in response to 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 Apr 16, 2017 5:41 AM (in response to Shekhar Tanji)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.
-
Re: how can i extract feature data from feature manager using api?
Shekhar Tanji Apr 19, 2017 9:59 AM (in response to Peter Brinkhuis)Thanks for the mismatch error. But going further other things are not working as expected. As you can see i have already used GetFeatureCount(true), but its returning some different value like 25, see watch below while i have only 5 features.
Is it possible to get it?. Also the featArray is returning null.
-
Re: how can i extract feature data from feature manager using api?
Peter Brinkhuis Apr 20, 2017 3:59 AM (in response to Shekhar Tanji)You can use Debug.Print swFeat.Name to see what the features actually are. You'll then see that there are a lot of hidden features like the sensors folder etc. You could create a program that excludes or includes certain features to get a more accurate count.
Maybe there is another way around your problem. Why is the feature count something you want to know? I've never seen a reason for that. Certainly with imported parts the amount of features can vary I guess. So what is the real problem that you are trying to solve?
-
-
-