10 Replies Latest reply on Jun 5, 2018 12:19 AM by Roland Schwarz

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

    Louise Cléroux

      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.

        • Re: Which property would tell me that a sheet metal part contains at least one bend?
          Roland Schwarz

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

          • Re: Which property would tell me that a sheet metal part contains at least one bend?
            Solid Air

            You could traverse the feature manager tree and look for the Flatten-<Base Bend> feature

            • Re: Which property would tell me that a sheet metal part contains at least one bend?
              Colin Poushay

              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

                • Re: Which property would tell me that a sheet metal part contains at least one bend?
                  Solid Air

                  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

                    • Re: Which property would tell me that a sheet metal part contains at least one bend?
                      Colin Poushay

                      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

                      • Re: Which property would tell me that a sheet metal part contains at least one bend?
                        Solid Air

                        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- <BaseBend> 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.

                         

                        Dim swApp As SldWorks.SldWorks
                        Dim swDoc As SldWorks.ModelDoc2
                        Dim swFeat As SldWorks.Feature
                        Dim swSubFeat As SldWorks.Feature
                        
                        
                        Sub main()
                        
                           Dim FoundBend As Boolean
                            
                            FoundBend = False
                        
                           Set swApp = Application.SldWorks
                            
                            Set swDoc = swApp.ActiveDoc
                            
                            Set swFeat = swDoc.FirstFeature
                            
                            Do Until swFeat Is Nothing
                            
                                If swFeat.GetTypeName2 = "FlatPattern" Then
                                
                                    Set swSubFeat = swFeat.GetFirstSubFeature
                                    
                                    Do Until swSubFeat Is Nothing
                                    
                                        If swSubFeat.GetTypeName2 = "UiBend" Then
                                        
                                            FoundBend = True
                                            
                                            Exit Do
                                            
                                        End If
                                    
                                        Set swSubFeat = swSubFeat.GetNextSubFeature
                                        
                                    Loop
                                    
                                End If
                                
                                If FoundBend Then Exit Do
                                
                                Set swFeat = swFeat.GetNextFeature
                            
                            Loop
                            
                            Set swApp = Nothing
                            Set swDoc = Nothing
                            Set swFeat = Nothing
                            Set swSubFeat = Nothing
                            
                            If FoundBend Then
                            
                                MsgBox "Part contains at least one sheet metal bend.", vbInformation + vbOKOnly, "Find Sheet Metal Bend"
                                
                            Else
                            
                                MsgBox "Part does not contain a sheet metal bend.", vbInformation + vbOKOnly, "Find Sheet Metal Bend"
                                    
                            End If
                            
                        End Sub
                        
                          • Re: Which property would tell me that a sheet metal part contains at least one bend?
                            Louise Cléroux

                            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

                      • Re: Which property would tell me that a sheet metal part contains at least one bend?
                        Roland Schwarz

                        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.