Can anyone tell my why features in the SW feature treehavecircular references?
For example, calling GetFirstSubFeature on an extrude featurewillreturn it'schild sketch as expected, but callingGetFirstSubFeatureon the sketch will return theparentextrude feature!? This is a circular reference andsuch occurrencesare generally considered very bad (AKA bugs) insoftwaredevelopment.
As a consequence of this behavior, when you attempt toenumerate(loop through) each node in the feature tree using'recursion' the macro enters an infinite loop. I have includeda macrobelow to demonstrate this. Don't worry, the macro does allowyou toexit the infinite loop - just press cancel in the dialog boxitshows for each node in the feature tree.
Using recursion to read nodes in a tree data structure is theonlyway to enumerate all the nodes without having a predefinedlimit tothe number of child levels in the tree. So, can anyone shedanylight on this seemingly insane design decision, or is it a bugwithSW?
Tim
Sub main() Dim swApp As SldWorks.SldWorks Set swApp=Application.SldWorks Dim swDoc As SldWorks.ModelDoc2 Set swDoc=swApp.ActiveDoc If Not swDoc Is Nothing ThenRecursiveReadswDoc.FirstFeature End IfEnd SubSubRecursiveRead(swFeature AsSldWorks.Feature) Do While Not swFeatureIs Nothing IfMsgBox(swFeature.Name, vbOKCancel) = vbCancel ThenExit Sub End IfRecursiveRead swFeature.GetFirstSubFeature SetswFeature =swFeature.GetNextFeature LoopEnd SubSolidworksApi macros
For example, calling GetFirstSubFeature on an extrude featurewillreturn it'schild sketch as expected, but callingGetFirstSubFeatureon the sketch will return theparentextrude feature!? This is a circular reference andsuch occurrencesare generally considered very bad (AKA bugs) insoftwaredevelopment.
As a consequence of this behavior, when you attempt toenumerate(loop through) each node in the feature tree using'recursion' the macro enters an infinite loop. I have includeda macrobelow to demonstrate this. Don't worry, the macro does allowyou toexit the infinite loop - just press cancel in the dialog boxitshows for each node in the feature tree.
Using recursion to read nodes in a tree data structure is theonlyway to enumerate all the nodes without having a predefinedlimit tothe number of child levels in the tree. So, can anyone shedanylight on this seemingly insane design decision, or is it a bugwithSW?
Tim
Sub main() Dim swApp As SldWorks.SldWorks Set swApp=Application.SldWorks Dim swDoc As SldWorks.ModelDoc2 Set swDoc=swApp.ActiveDoc If Not swDoc Is Nothing ThenRecursiveReadswDoc.FirstFeature End IfEnd SubSubRecursiveRead(swFeature AsSldWorks.Feature) Do While Not swFeatureIs Nothing IfMsgBox(swFeature.Name, vbOKCancel) = vbCancel ThenExit Sub End IfRecursiveRead swFeature.GetFirstSubFeature SetswFeature =swFeature.GetNextFeature LoopEnd SubSolidworksApi macros