Josh Hixon wrote:
My macro is finding cutlist folders that I have not a clue where they are. I can not physically find them in the feature tree. The only way I see them is if the loop finds them. Someone, please help me understand why these extras are there and how to get rid of them.
Here are the part and my macro that I am using.
You will see that the BOM spits out two raw material numbers when there is only one weldment material selected.
Cut list item 6 is the first one that comes up that has no feature that I can find in SolidWorks.
PS I have made excel visible and commented out the saving portion to better serve the purpose of seeing what is going on.
I don't have SW2018 so I can't open your part (still running 2017) however, you can find it by
If swFeat.GetTypeName() = "CutListFolder" Then
dim CutListFolderString as string = """SW-CutListItemName@" & swModel.GetTitle + ".SLDPRT"""
The funny part about your code is that you are finding the second set of cut list folders that are present in models. The cut list folders you are looking for are actually sub features under the cut list folder. The second set of folders seem to always be present in weldment models and I have no idea what they except they remind me of an XML end tag. There are six hidden cut list folders which would normally indicate there are differences between the as welded and as machined configuration but I do not immediately see any differences between them (more research). Below is my code to traverse sub features so you can see what I am talking about.
Dim swApp As SldWorks.SldWorks Dim swDoc As SldWorks.ModelDoc2 Dim swFeat As SldWorks.Feature Dim swSubFeat As SldWorks.Feature Sub TraverseAgain() Set swApp = Application.SldWorks Set swDoc = swApp.ActiveDoc Set swFeat = swDoc.FirstFeature Do Until swFeat Is Nothing Debug.Print swFeat.Name, swFeat.GetTypeName2 Set swSubFeat = swFeat.GetFirstSubFeature Do Until swSubFeat Is Nothing Debug.Print "..... "; swSubFeat.Name, swSubFeat.GetTypeName2 Set swSubFeat = swSubFeat.GetNextSubFeature Loop Set swFeat = swFeat.GetNextFeature Loop Set swFeat = Nothing Set swSubFeat = Nothing Set swDoc = Nothing Set swApp = Nothing End Sub
Thank you for this! I spent a bunch of time trying to figure out how to get to subfeatures in a feature folder, never did figure it out, but this answers that, as well as why there are crazy extra features going on. I will just loop through cut list folder I want instead of the whole tree, faster (milliseconds I know), and I don't end up with features I didn't really want. Thank you so much for taking the time to look into this!
Here are a few more example macros you might be interested in; look for these in API help.
Get Bodies in Body Folders Example
Get Solid Bodies from Cut-list Folders and Get Custom Properties Example (VBA)
Traverse FeatureManager Design Tree Example
So still working this out, I am now going directly to the sold bodies folder, but the hidden bodies are still there. how do I delete the whole cutlist so I can set it back to auto create the cutlist? setting auto update and whatnot is all easy enough, I am having a tough time figuring out how to delete them though, preferably without looping through the cutlist again.
I did more research and found if I delete the existing cut list folders (first un-checking Create Cut List Automatically and Update Automatically) then recreating the cut list folders by checking Create Cut List Automatically, only 8 folders are created. If I had to guess, you probably made changes to your model after creating the cut list and those changes re-arranged which folders which bodies were in. Unfortunately SolidWorks sometimes hides these no longer used folders instead of deleting them. Do not know if I answered your questions but welcome to the world under the SolidWorks hood. There are all kinds of hidden features lurking in SolidWorks models, assemblies and drawings which may explain why they are unstable at times.