Counting UP and DOWN bends

By Xiaodong Liang

The bend information is stored in FlatBendResult. The property IsDirectionUp tells if the bend is up or down. The following code dumps the information of FlatBendResult collection thus we could know how many bends are UP / Down.

Public Sub GetBendResults()
 
        Dim inventorAppType As Type = 
    System.Type.GetTypeFromProgID("Inventor.Application")
 
Dim _InvApplication As Inventor.Application = 
System.Runtime.InteropServices.Marshal.
GetActiveObject("Inventor.Application")
 
    ' Set a reference to the sheet metal document.
    ' This assumes a part document is active.
    Dim oPartDoc As PartDocument
    oPartDoc = _InvApplication.ActiveDocument
 
    ' Make sure the document is a sheet metal document.
    If oPartDoc.SubType   _
        "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        MsgBox("A sheet metal document must be open.")
        Exit Sub
    End If
 
    Dim oSheetMetalCompDef As SheetMetalComponentDefinition
    oSheetMetalCompDef = oPartDoc.ComponentDefinition
 
    If (Not oSheetMetalCompDef.HasFlatPattern) Then
        oSheetMetalCompDef.Unfold()
    End If
 
    Dim oFlatPattern As FlatPattern
    oFlatPattern = oSheetMetalCompDef.FlatPattern       
 
    Dim oBendResult As FlatBendResult
    For Each oBendResult In oFlatPattern.FlatBendResults
 
        ' Internal Name
        Dim strResult As String
        strResult = "Internal Name: " & _
            oBendResult.InternalName & ", "
 
        ' top or bottom
        If oBendResult.IsOnBottomFace Then
            strResult = strResult & "On Bottom, "
        Else
            strResult = strResult & "On Top, "
        End If
 
        ' angle
        strResult = strResult & "Angle: " & _
            _InvApplication.ActiveDocument.
            UnitsOfMeasure.GetStringFromValue(
                oBendResult.Angle, 
                UnitsTypeEnum.kDefaultDisplayAngleUnits) & ", "
 
        ' Inner Radius
        strResult = strResult &  _ 
            "Inner Radius: " &  _ 
            _InvApplication.ActiveDocument.
            UnitsOfMeasure.GetStringFromValue(
                oBendResult.InnerRadius, 
                UnitsTypeEnum.kDefaultDisplayLengthUnits) & ", "
 
        ' bend direction
        If oBendResult.IsDirectionUp Then
            strResult = 
                strResult & "Bend Direction: " & "Bend Up"
        Else
            strResult = 
                strResult & "Bend Direction: " & "Bend Down"
        End If  
 
        Debug.Print(strResult)
    Next       
 
End Sub

Comments

One response to “Counting UP and DOWN bends”

  1. Lbjepsen Avatar
    Lbjepsen

    When running this in Ilogic in Inventor 2020 the internal name looks like this: 9:4,-1,235,1 any suggestions on how to solve it? It also counts each bend double??

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading