13 Replies Latest reply on Aug 2, 2018 9:29 AM by Louise Cléroux

    Which feature would tell me the bend radius of each bend?

    Louise Cléroux

      I have written (with the help of many on this forum) a macro to identify if the part has any bend, See the following link for the complete macro: Which property would tell me that a sheet metal part contains at least one bend?

       

      Where can I find information on the features accessible when swFeat.GetTypeName2 = "FlatPattern" ?

       

      I would like to get the actual bend radius of each bend in the part to identify on which machine the part has to go to. I am not looking for the default minimal bend radius based on the material but the actual bend radius which may be bigger. We have sheet metal parts that are rolled formed and/or bent. I want my macro to be able to distinguish between the two process. It is easil done if I can get access to the actual bend radius of each bend.

       

      Thanks everyone!

        • Re: Which feature would tell me the bend radius of each bend?
          Mr Omkar Deshpande

          I think this might help you -

           

          how to check sheetmetal parts for a bend radius of 0

           

          Just replace 'Application.Cells ..... = " to Debug.Print

          • Re: Which feature would tell me the bend radius of each bend?
            Louise Cléroux

            Thank everyone.

             

            The value I am getting is the baseline radius for the material type not the actual rolled radius.

             

            Here is a print screen of my design tree along with the name of the features as I understand them (sorry for the french).

            I realised observing the name of the Features in debug mode that the features present in a part are design dependant. Is there a universal way to navigate the subfeatures one by one without knowing in advance what they are or how many there are? That could help me understand the structure of the data. Any of this documented anywhere?

             

            Thanks everyone.

              • Re: Which feature would tell me the bend radius of each bend?
                Nilesh Patel

                I have modified the macro and this will give you the bend radius you want. It will give you the value in MM so you will have to change it to suit your needs.

                 

                Option Explicit
                
                
                '------------------------------------------------
                Dim swApp As SldWorks.SldWorks
                Dim swModel As ModelDoc2
                Dim swSelMgr As SldWorks.SelectionMgr
                Dim swFeat As SldWorks.Feature
                Dim swSubFeat As SldWorks.Feature
                Dim bRet As Boolean
                Dim lRet As Long
                Dim gaugeTableFile As String
                
                
                Sub Process_CustomBendAllowance _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swCustBend As SldWorks.CustomBendAllowance _
                )
                
                
                    Debug.Print "      BendAllowance    = " & swCustBend.BendAllowance * 1000# & " mm"
                    Debug.Print "      BendDeduction    = " & swCustBend.BendDeduction * 1000# & " mm"
                    Debug.Print "      BendTableFile    = " & swCustBend.BendTableFile
                    Debug.Print "      KFactor          = " & swCustBend.KFactor
                    Debug.Print "      Type            = " & swCustBend.Type
                
                
                End Sub
                
                
                Sub Process_SMBaseFlange _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swBaseFlange                As SldWorks.BaseFlangeFeatureData
                    Set swBaseFlange = swFeat.GetDefinition
                
                
                    Debug.Print "    BendRadius = " & swBaseFlange.BendRadius * 1000# & " mm"
                
                
                End Sub
                Sub Process_SheetMetal _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swSheetMetal  As SldWorks.SheetMetalFeatureData
                    Set swSheetMetal = swFeat.GetDefinition
                
                
                    Dim swCustBend As SldWorks.CustomBendAllowance
                    Set swCustBend = swSheetMetal.GetCustomBendAllowance
                    Debug.Print "    BendRadius = " & swSheetMetal.BendRadius * 1000# & " mm"
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                
                    lRet = swSheetMetal.GetUseGaugeTable(bRet, gaugeTableFile)
                    Debug.Print "    Use gauge table? " & bRet
                    Debug.Print "      Error code as defined in swSheetMetalModifierError_e: " & lRet
                
                
                End Sub
                
                
                Sub Process_SM3dBend _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swSketchBend As SldWorks.SketchedBendFeatureData
                    Dim swCustBend As SldWorks.CustomBendAllowance
                
                
                    Set swSketchBend = swFeat.GetDefinition
                    Set swCustBend = swSketchBend.GetCustomBendAllowance
                
                
                    Debug.Print "    UseDefaultBendAllowance = " & swSketchBend.UseDefaultBendAllowance
                    Debug.Print "    UseDefaultBendRadius = " & swSketchBend.UseDefaultBendRadius
                    Debug.Print "    BendRadius = " & swSketchBend.BendRadius * 1000# & " mm"
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                End Sub
                
                
                Sub Process_SMMiteredFlange _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swMiterFlange As SldWorks.MiterFlangeFeatureData
                    Set swMiterFlange = swFeat.GetDefinition
                
                
                    Debug.Print "    UseDefaultBendAllowance = " & swMiterFlange.UseDefaultBendAllowance
                    Debug.Print "    UseDefaultBendRadius = " & swMiterFlange.UseDefaultBendRadius
                    Debug.Print "    BendRadius = " & swMiterFlange.BendRadius * 1000# & " mm"
                
                
                End Sub
                
                
                Sub Process_Bends _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swBends As SldWorks.BendsFeatureData _
                )
                
                
                    Dim swCustBend  As SldWorks.CustomBendAllowance
                    Set swCustBend = swBends.GetCustomBendAllowance
                
                
                    Debug.Print "    BendRadius                = " & swBends.BendRadius * 1000# & " mm"
                    Debug.Print "    UseDefaultBendAllowance    = " & swBends.UseDefaultBendAllowance
                    Debug.Print "    UseDefaultBendRadius      = " & swBends.UseDefaultBendRadius
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                End Sub
                
                
                Sub Process_ProcessBends _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swBends                    As SldWorks.BendsFeatureData
                    Set swBends = swFeat.GetDefinition
                
                
                    Process_Bends swApp, swModel, swBends
                
                
                End Sub
                Sub Process_FlattenBends _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swBends                    As SldWorks.BendsFeatureData
                    Set swBends = swFeat.GetDefinition
                
                
                    Process_Bends swApp, swModel, swBends
                
                
                End Sub
                Sub Process_EdgeFlange _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swEdgeFlange                As SldWorks.EdgeFlangeFeatureData
                    Set swEdgeFlange = swFeat.GetDefinition
                
                
                    Debug.Print "    UseDefaultBendRadius = " & swEdgeFlange.UseDefaultBendRadius
                    Debug.Print "    BendRadius = " & swEdgeFlange.BendRadius * 1000# & " mm"
                
                
                End Sub
                
                
                
                Sub Process_FlatPattern _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swFlatPatt                  As SldWorks.FlatPatternFeatureData
                    Set swFlatPatt = swFeat.GetDefinition
                
                
                    Debug.Print "      Simplify bends? " & swFlatPatt.SimplifyBends
                
                
                End Sub
                Sub Process_Hem _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swHem                      As SldWorks.HemFeatureData
                    Dim swCustBend                  As SldWorks.CustomBendAllowance
                
                
                    Set swHem = swFeat.GetDefinition
                    Set swCustBend = swHem.GetCustomBendAllowance
                
                
                    Debug.Print "    UseDefaultBendAllowance = " & swHem.UseDefaultBendAllowance
                    Debug.Print "    Radius = " & swHem.Radius * 1000# & " mm"
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                End Sub
                Sub Process_Jog _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swJog                      As SldWorks.JogFeatureData
                    Dim swCustBend                  As SldWorks.CustomBendAllowance
                
                
                    Set swJog = swFeat.GetDefinition
                    Set swCustBend = swJog.GetCustomBendAllowance
                
                
                    Debug.Print "    UseDefaultBendAllowance = " & swJog.UseDefaultBendAllowance
                    Debug.Print "    UseDefaultBendRadius = " & swJog.UseDefaultBendRadius
                    Debug.Print "    BendRadius = " & swJog.BendRadius * 1000# & " mm"
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                End Sub
                Sub Process_LoftedBend _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swLoftBend                  As SldWorks.LoftedBendsFeatureData
                    Set swLoftBend = swFeat.GetDefinition
                
                
                
                
                
                End Sub
                Sub Process_Rip _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swRip                      As SldWorks.RipFeatureData
                    Set swRip = swFeat.GetDefinition
                
                
                
                
                
                End Sub
                Sub Process_CornerFeat _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swCloseCorner              As SldWorks.ClosedCornerFeatureData
                    Set swCloseCorner = swFeat.GetDefinition
                
                
                
                
                
                End Sub
                
                
                
                Sub Process_OneBend _
                ( _
                    swApp As SldWorks.SldWorks, _
                    swModel As SldWorks.ModelDoc2, _
                    swFeat As SldWorks.Feature _
                )
                
                
                    Debug.Print "    +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
                
                
                    Dim swOneBend  As SldWorks.OneBendFeatureData
                    Dim swCustBend As SldWorks.CustomBendAllowance
                
                
                    Set swOneBend = swFeat.GetDefinition
                    Set swCustBend = swOneBend.GetCustomBendAllowance
                
                
                    Debug.Print "      BendRadius = " & swOneBend.BendRadius * 1000# & " mm"
                    Debug.Print "      UseDefaultBendAllowance = " & swOneBend.UseDefaultBendAllowance
                    Debug.Print "      UseDefaultBendRadius = " & swOneBend.UseDefaultBendRadius
                
                
                    Process_CustomBendAllowance swApp, swModel, swCustBend
                
                
                End Sub
                
                
                
                Sub main()
                
                
                    Set swApp = Application.SldWorks
                    Set swModel = swApp.ActiveDoc
                    Set swSelMgr = swModel.SelectionManager
                    Set swFeat = swModel.FirstFeature
                
                
                    Debug.Print "File = " & swModel.GetPathName
                
                
                    Do While Not swFeat Is Nothing
                        ' Process top-level sheet metal features
                        Select Case swFeat.GetTypeName
                            Case "SMBaseFlange"
                                Process_SMBaseFlange swApp, swModel, swFeat
                
                
                            Case "SheetMetal"
                                Process_SheetMetal swApp, swModel, swFeat
                
                
                            Case "SM3dBend"
                                Process_SM3dBend swApp, swModel, swFeat
                
                
                            Case "SMMiteredFlange"
                                Process_SMMiteredFlange swApp, swModel, swFeat
                
                
                            Case "ProcessBends"
                                Process_ProcessBends swApp, swModel, swFeat
                
                
                            Case "FlattenBends"
                                Process_FlattenBends swApp, swModel, swFeat
                
                
                            Case "EdgeFlange"
                                Process_EdgeFlange swApp, swModel, swFeat
                
                
                            Case "FlatPattern"
                                Process_FlatPattern swApp, swModel, swFeat
                
                
                            Case "Hem"
                                Process_Hem swApp, swModel, swFeat
                
                
                            Case "Jog"
                                Process_Jog swApp, swModel, swFeat
                
                
                            Case "LoftedBend"
                                Process_LoftedBend swApp, swModel, swFeat
                
                
                            Case "Rip"
                                Process_Rip swApp, swModel, swFeat
                
                
                            Case "CornerFeat"
                                Process_CornerFeat swApp, swModel, swFeat
                
                
                            Case Else
                                ' Probably not a sheet metal feature
                
                
                        End Select
                
                
                        ' process sheet metal sub-features
                        Set swSubFeat = swFeat.GetFirstSubFeature
                
                
                        Do While Not swSubFeat Is Nothing
                            'Debug.Print swSubFeat.GetTypeName
                            Select Case swSubFeat.GetTypeName
                                Case "SketchBend"
                                    Process_OneBend swApp, swModel, swSubFeat
                                   
                                Case "OneBend"
                                    Process_OneBend swApp, swModel, swSubFeat
                
                
                                Case Else
                                    ' Probably not a sheet metal feature
                            End Select
                
                
                            Set swSubFeat = swSubFeat.GetNextSubFeature()
                        Loop
                
                
                        Set swFeat = swFeat.GetNextFeature
                
                
                    Loop
                
                
                End Sub
                

                 

                 

                I realised observing the name of the Features in debug mode that the features present in a part are design dependant. Is there a universal way to navigate the subfeatures one by one without knowing in advance what they are or how many there are? That could help me understand the structure of the data. Any of this documented anywhere?

                 

                Doesn't macro do exactly this (navigate features and sub features one by one)?

                  • Re: Which feature would tell me the bend radius of each bend?
                    Louise Cléroux

                    I will give it a try tomorrow. Thanks. I do not know how to attach my part file??

                     

                    Why is it that we have to know the type of the subfeatures to get to the values they hold? Is this documented somewhere: feature, subfeature, values.

                      • Re: Which feature would tell me the bend radius of each bend?
                        Nilesh Patel

                        Hi Louise,

                        Louise Cléroux wrote:

                         

                        I do not know how to attach my part file??

                        Have a look at this thread: How can I attach a file to a forum post?

                         

                        Louise Cléroux wrote:

                         

                        Why is it that we have to know the type of the subfeatures to get to the values they hold? Is this documented somewhere: feature, subfeature, values.

                         

                        I am not a professional but I will try to explain you in simple language.

                        The feature could be anything e.g. Boss-extrude, Base flange, Edge flange. You can rename the feature to any name. So by just knowing the name of the feature doesn't identify the type of feature and therefore you need to get its type to know what sort of feature it is. Different features have different parameters e.g. Boss extrude feature has depth, starting condition, end condition, direction etc. whereas Base flange will have thickness, bend radius etc. So once you know the type of feature, you can access these parameters and modify if required.

                         

                        You can access the feature directly if you know the name and then determine what type of feature it is or you can pre-select them in feature tree before running the macro to access it. This will eliminate feature traverse.

                         

                        In regards to documentation, in my opinion offline API help is the best. It has lots of information, remakes and example to help you learn.

                         

                        Hope this will help you.

                         

                        Regards,

                        Nilesh

                  • Re: Which feature would tell me the bend radius of each bend?
                    Louise Cléroux

                    I have switch my Soliworks to english . And I was able to mix and match code to scan through the feature (name, type and their bend radius) and subfeatures (only name and type) of a part. I am still unable to get to the bend radiuses of the subfeatures because I do not know how to adress them. Any help or guidance would be appreciated.

                     

                    Here is the code, some declarations are not used but part of things I have tried and that did not work:

                     

                    Dim swApp As SldWorks.SldWorks

                    Dim swModelDoc As SldWorks.ModelDoc2

                    Dim swSelMgr As SldWorks.SelectionMgr

                    Dim swFeat As SldWorks.Feature

                    Dim swSubFeat As SldWorks.Feature

                     

                    Dim swBaseFlange As SldWorks.BaseFlangeFeatureData

                    Dim swSheetMetal As SldWorks.SheetMetalFeatureData

                    Dim swSketchBend As SldWorks.SketchedBendFeatureData

                    Dim swBaseFlangeBend As SldWorks.SketchedBendFeatureData

                    Dim swBends As SldWorks.BendsFeatureData

                    Dim swEdgeFlange As SldWorks.EdgeFlangeFeatureData

                    Dim swMiterFlange As SldWorks.MiterFlangeFeatureData

                    Dim swEdgeFlangeBend As SldWorks.OneBendFeatureData

                     

                    Option Explicit

                     

                    Sub main()

                     

                        Set swApp = Application.SldWorks

                        Set swModelDoc = swApp.ActiveDoc

                        Set swSelMgr = swModelDoc.SelectionManager

                        Set swFeat = swModelDoc.FirstFeature

                     

                        Do While Not swFeat Is Nothing

                     

                            Select Case swFeat.GetTypeName

                     

                              Case "SMBaseFlange"

                     

                                    Set swBaseFlange = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swBaseFlange.BendRadius * 39.37 & "  inch"

                                  

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                     

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                     

                     

                                Case "SheetMetal"

                     

                                    Set swSheetMetal = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swSheetMetal.BendRadius * 39.37 & "  inch"

                     

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                     

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                     

                                Case "SM3dBend"

                     

                                    Set swSketchBend = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swSketchBend.BendRadius * 39.37 & "  inch"

                     

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                     

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                                  

                                Case "ProcessBends"

                     

                                    Set swBends = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swBends.BendRadius * 39.37 & "  inch"

                     

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                     

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                     

                                Case "EdgeFlange"

                     

                                    Set swEdgeFlange = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swEdgeFlange.BendRadius * 39.37 & "  inch"

                     

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                                              

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                                  

                                Case "SMMiteredFlange"

                     

                                    Set swMiterFlange = swFeat.GetDefinition

                     

                                    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

                                    Debug.Print "    BendRadius = " & swMiterFlange.BendRadius * 39.37 & "  inch"

                     

                                    Set swSubFeat = swFeat.GetFirstSubFeature

                     

                                    Do While Not swSubFeat Is Nothing

                     

                                        Debug.Print "     +" & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"

                     

                                        Set swSubFeat = swSubFeat.GetNextSubFeature()

                     

                                    Loop

                                  

                                Case Else

                     

                                    ' Probably not a sheet metal feature

                     

                            End Select

                     

                            Set swFeat = swFeat.GetNextFeature

                     

                        Loop

                     

                    End Sub

                     

                    And here is the immediate window results: