PPT_LOGO_4b
‹#›
Autodesk Confidential Information January 2010
Access to Flat Pattern Bend Information
§Get the bend and fold lines from the flat pattern.  The EdgeType argument allows you to specify what you want (fold down bend lines, fold up bend lines, or mold lines).
§ FlatPattern.GetEdgesOfType( EdgeType As FlatPatternEdgeTypeEnum, _
   [TopFaceEdges As Boolean = True]) As Edges
§
§Bend and mold lines are represented as Edge objects.  These Edge objects represent wireframe edges and are not associated with a surface or solid.  For wireframe edges, the Wire Property on the Edge will return a Wire object, indicating it is a wireframe edge.
§
§The FlatPattern.FlatBendResults provides access to the bend information, (number of bends, bend up or down, bend angle, inside radius, etc.), and the associated Edge that represents the bend.
•
    '/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    '// Use: Gets Flat bend info for active doc
    '//
    '/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Public Sub GetBendResults()

        ' 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

            Dim strResult As String
            strResult = "Internal Name: " & oBendResult.InternalName & ", "

            If oBendResult.IsOnBottomFace Then
                strResult = strResult & "On Bottom, "
            Else
                strResult = strResult & "On Top, "
            End If

            strResult = strResult & "Angle: " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.Angle, UnitsTypeEnum.kDefaultDisplayAngleUnits) & ", "

            strResult = strResult & "Inner Radius: " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.InnerRadius, UnitsTypeEnum.kDefaultDisplayLengthUnits) & ", "

            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


    'User has to select a bend line in a drawing document
    'that belongs to the flat bend pattern of a SheetMetalPart
    Public Sub GetBendResultFromSelectedCurve()

        'Gets the selected curve segment
        Dim oDwCurveSegment As DrawingCurveSegment
        oDwCurveSegment = _InvApplication.ActiveDocument.SelectSet.Item(1)

        'Gets full drawing curve from the segment
        Dim oDrawingCurve As DrawingCurve
        oDrawingCurve = oDwCurveSegment.Parent

        'Gets edge
        Dim oEdge As Edge
        oEdge = oDrawingCurve.ModelGeometry

        'Retrieves component definition from the edge
        Dim oSMDef As SheetMetalComponentDefinition
        oSMDef = oEdge.Parent.ComponentDefinition

        Dim oFlatPattern As FlatPattern
        oFlatPattern = oSMDef.FlatPattern

        'Gets flat bend result corresponding to the edge
        Dim oBendResult As FlatBendResult
        oBendResult = oFlatPattern.FlatBendResults.Item(oEdge)


        'Prints Flat Bend Results
        Debug.Print("---------------- Flat Bend Infos ----------------")

        Debug.Print("Internal Name: " & oBendResult.InternalName)

        If oBendResult.IsOnBottomFace Then
            Debug.Print("Bend On Bottom Face")
        Else
            Debug.Print("Bend On Top Face")
        End If

        Debug.Print("Bend Angle = " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.Angle, UnitsTypeEnum.kDefaultDisplayAngleUnits))

        Debug.Print("Bend Radius = " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.InnerRadius, UnitsTypeEnum.kDefaultDisplayLengthUnits))

        If oBendResult.IsDirectionUp Then
            Debug.Print("Bend Direction: " & "Bend Up")
        Else
            Debug.Print("Bend Direction: " & "Bend Down")
        End If

        Debug.Print("-------------------------------------------------")

    End Sub

    Public Sub GetBendLines()

        Dim oSheetMetalCompDef As SheetMetalComponentDefinition
        oSheetMetalCompDef = _InvApplication.ActiveDocument.ComponentDefinition

        Dim oFlatPattern As FlatPattern
        oFlatPattern = oSheetMetalCompDef.FlatPattern

        Dim oBendResults As FlatBendResults
        oBendResults = oFlatPattern.FlatBendResults
        Debug.Print("Nb. Bend Lines = " & oBendResults.Count / 2)

        Dim oBendResult As FlatBendResult
        For Each oBendResult In oBendResults

            Debug.Print("---------------- Flat Bend Infos ----------------")

            Debug.Print("Internal Name: " & oBendResult.InternalName)

            If oBendResult.IsOnBottomFace Then
                Debug.Print("Bend On Bottom Face")
            Else
                Debug.Print("Bend On Top Face")
            End If

            Debug.Print("Bend Angle = " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.Angle, UnitsTypeEnum.kDefaultDisplayAngleUnits))

            Debug.Print("Bend Radius = " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(oBendResult.InnerRadius, UnitsTypeEnum.kDefaultDisplayLengthUnits))

            If oBendResult.IsDirectionUp Then
                Debug.Print("Bend Direction: " & "Bend Up")
            Else
                Debug.Print("Bend Direction: " & "Bend Down")
            End If

        Next

    End Sub