This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Dim swFeat As SldWorks.Feature
Set swFeat = swModel.FirstFeature
swModel.ClearSelection2 TrueWhileNot swFeat IsNothingIf IsFolder(swFeat) ThenIfNot FolderHasFeatures(swFeat.GetSpecificFeature2()) Then
swFeat.Select2 True, -1
EndIfEndIfDim swSubFeat As SldWorks.Feature
Set swSubFeat = swFeat.GetFirstSubFeature
WhileNot swSubFeat IsNothingIf IsFolder(swSubFeat) ThenIfNot FolderHasFeatures(swSubFeat.GetSpecificFeature2()) Then
swSubFeat.Select2 True, -1
EndIfEndIfSet swSubFeat = swSubFeat.GetNextSubFeature
Wend
Set swFeat = swFeat.GetNextFeature
Wend
swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed
EndSubFunction IsFolder(feat As SldWorks.Feature) AsBooleanConst END_FOLDER_TAG AsString = "___EndTag___"
IsFolder = feat.GetTypeName2() = "FtrFolder"And Right(feat.Name, Len(END_FOLDER_TAG)) <> END_FOLDER_TAG
EndFunctionFunction FolderHasFeatures(folder As SldWorks.FeatureFolder) AsBooleanIf folder.GetFeatureCount() = 0 Then
FolderHasFeatures = FalseElseDim vFeats AsVariant
vFeats = folder.GetFeatures()
Dim i AsIntegerFor i = 0 To UBound(vFeats)
Dim swFeat As SldWorks.Feature
Set swFeat = vFeats(i)
If IsFolder(swFeat) ThenIf FolderHasFeatures(swFeat.GetSpecificFeature2()) Then
FolderHasFeatures = TrueExitFunctionEndIfElse
FolderHasFeatures = TrueExitFunctionEndIfNext
FolderHasFeatures = FalseEndIfEndFunction