I want to write a macro that will look up the appropriate property of a sheet metal part to determine if the said part has at least one bend. Does anyone know if such a property exist, and if so, what is the name of that property? I do not need to know how many bends just if there is at least one bend. This will be included in a macro that will write the production routing of the part: does it need to go the the bending department or not?
Thanks.
SolidworksApi macros
Look through the feature tree for sheet metal features and get the bend count there.
You could traverse the feature manager tree and look for the Flatten- feature
Not sure if OneBendFeatureData is what you need.
Hi Louise,
perhaps the easiest way to do this would be to get the Cutlist and check the 'Bends' property to see if there's more than zero.
An alternative would be similar to what Solid Air said. The Flatpattern feature has a sub-feature called bend lines, which is a sketch. There are no bends in the part if this sketch has no segments.
Colin
Colin,
I was not suggesting using the bend-lines feature. It will not tell you if you have bends because SolidWorks creates this feature for even a sheet metal feature without any bends in it. If you look at my screen shot below both Flat-Pattern features have a Bend-Lines feature below it but the second is just a flat with now bends in it
Sorry, I meant that it was a similar approach because it also analyzes the flat-pattern feature.
I believe you can use the 'bend-lines' feature to determine if there are bends in the part using these steps:
1) use the 'Feature::GetSpecificFeature2' method on the feature, which should be a Sketch object
2) use 'Sketch::GetSketchSegments' and check the size of array returned
Just as there are several ways to create a feature in SolidWorks, there are several ways to write a macro that finds if the part contains a sheet metal bend. For me, I like to use API call GetTypeName2 because users cannot rename them like they can features in the tree. Through experimentation, I found the type name for the Flatten- feature is "UiBend". My coding suggestion to find it is below.
Other Notes: This code is not document dependent (except you must have an active document) for it to work.
Thanks everyone and especialy SolidAir!
In case it may be helpful to someone else in the future, here is the final code to my macro:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swCustProp As SldWorks.CustomPropertyManager
Sub main()
Dim FoundBend As Boolean
FoundBend = False
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Do Until FoundBend Or swFeat Is Nothing
If swFeat.GetTypeName2 = "FlatPattern" Then
Set swSubFeat = swFeat.GetFirstSubFeature
Do Until FoundBend Or swSubFeat Is Nothing
If swSubFeat.GetTypeName2 = "UiBend" Then
FoundBend = True
End If
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop
If FoundBend Then
MsgBox "At least one bend was found", vbInformation + vbOKOnly, "Looking for bends"
Set swCustProp = swModel.Extension.CustomPropertyManager("")
swCustProp.Add3 "Bends", 30, "Yes", 1
Else
MsgBox "No bends were found", vbInformation + vbOKOnly, "Looking for bends"
Set swCustProp = swModel.Extension.CustomPropertyManager("")
swCustProp.Add3 "Bends", 30, " No", 1
End If
End Sub
Glad to see you have yourself the right answer. Saves all the nasty effort of actually giving credit to the person who helped you most.
much better