Which property would tell me that a sheet metal part contains at least one bend?

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
Answers 10
RS
RS 2018-05-28 Best Answer

Look through the feature tree for sheet metal features and get the bend count there.

SA
SA 2018-05-28

You could traverse the feature manager tree and look for the Flatten- feature

DG
DG 2018-05-28

Not sure if OneBendFeatureData is what you need.

MR
MR 2018-05-28

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

SA
SA 2018-05-28

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

comment imagecomment image
MR
MR 2018-05-28

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

SA
SA 2018-05-28

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.

<p>Dim swApp As SldWorks.SldWorks</p><p>Dim swDoc As SldWorks.ModelDoc2</p><p>Dim swFeat As SldWorks.Feature</p><p>Dim swSubFeat As SldWorks.Feature</p><p></p><p></p><p>Sub main()</p><p></p><p>   Dim FoundBend As Boolean</p><p>    </p><p>    FoundBend = False</p><p></p><p>   Set swApp = Application.SldWorks</p><p>    </p><p>    Set swDoc = swApp.ActiveDoc</p><p>    </p><p>    Set swFeat = swDoc.FirstFeature</p><p>    </p><p>    Do Until swFeat Is Nothing</p><p>    </p><p>        If swFeat.GetTypeName2 = "FlatPattern" Then</p><p>        </p><p>            Set swSubFeat = swFeat.GetFirstSubFeature</p><p>            </p><p>            Do Until swSubFeat Is Nothing</p><p>            </p><p>                If swSubFeat.GetTypeName2 = "UiBend" Then</p><p>                </p><p>                    FoundBend = True</p><p>                    </p><p>                    Exit Do</p><p>                    </p><p>                End If</p><p>            </p><p>                Set swSubFeat = swSubFeat.GetNextSubFeature</p><p>                </p><p>            Loop</p><p>            </p><p>        End If</p><p>        </p><p>        If FoundBend Then Exit Do</p><p>        </p><p>        Set swFeat = swFeat.GetNextFeature</p><p>    </p><p>    Loop</p><p>    </p><p>    Set swApp = Nothing</p><p>    Set swDoc = Nothing</p><p>    Set swFeat = Nothing</p><p>    Set swSubFeat = Nothing</p><p>    </p><p>    If FoundBend Then</p><p>    </p><p>        MsgBox "Part contains at least one sheet metal bend.", vbInformation + vbOKOnly, "Find Sheet Metal Bend"</p><p>        </p><p>    Else</p><p>    </p><p>        MsgBox "Part does not contain a sheet metal bend.", vbInformation + vbOKOnly, "Find Sheet Metal Bend"</p><p>            </p><p>    End If</p><p>    </p><p>End Sub</p>
LC
LC 2018-06-04

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

RS
RS 2018-06-04

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.

RS
RS 2018-06-05

much better