Number of bends of sheet metal part and direction

Number of bends of sheet metal part and direction

Ahmed.shawkyXTZHN
Enthusiast Enthusiast
930 Views
13 Replies
Message 1 of 14

Number of bends of sheet metal part and direction

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi All , 

is it possible to get number of bends for sheet metal parts and and how many bends up and how many down to be shown in drawing as a table , thanks.

0 Likes
Accepted solutions (1)
931 Views
13 Replies
Replies (13)
Message 2 of 14

JelteDeJong
Mentor
Mentor

You can try this:

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim refDoc As PartDocument = sheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument
Dim refDef As SheetMetalComponentDefinition = refDoc.ComponentDefinition
Dim flatPattern = refDef.FlatPattern

Dim ups = 0
Dim downs = 0
For Each result As FlatBendResult In flatPattern.FlatBendResults
    If (result.IsOnBottomFace) Then Continue For
    If (result.IsDirectionUp) Then
        ups += 1
    Else
        downs += 1
    End If
Next

Dim insertPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
Dim headers = New String() {"Direction", "number"}

Dim table = sheet.CustomTables.Add("Bends", insertPoint, 2, 2, headers)
table.Rows.Item(1).Item(1).Value = "Up"
table.Rows.Item(1).Item(2).Value = ups
table.Rows.Item(2).Item(1).Value = "Down"
table.Rows.Item(2).Item(2).Value = downs

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 14

JelteDeJong
Mentor
Mentor

You also might want to have a look at my blog post: Automatically generate bend dimensions 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
thanks for your response , it's working fine with part , is it possible that it can run from assembly so all will come in one table along with cutting list , thanks.
0 Likes
Message 5 of 14

JelteDeJong
Mentor
Mentor
Accepted solution

try this:

Public Class ThisRule
    Sub Main()

        Dim doc As DrawingDocument = ThisDoc.Document
        Dim sheet As Sheet = doc.ActiveSheet
        Dim refDoc As Document = sheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

        Dim infos As New List(Of DocumentInfo)
        If (refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            If (refDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
                infos.Add(New DocumentInfo(refDoc))
            End If
        Else
            For Each assDoc As Document In refDoc.AllReferencedDocuments
                If (assDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
                    If (assDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
                        infos.Add(New DocumentInfo(assDoc))
                    End If
                End If
            Next
        End If

        If (infos.Count = 0) Then
            MsgBox("No sheetmetal found.")
            Return
        End If

        Dim insertPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
        Dim headers = New String() {"Part", "Size", "Up", "Down"}

        Dim table = sheet.CustomTables.Add("Bends", insertPoint, headers.Length, infos.Count, headers)
        For i = 1 To infos.Count
            Dim row = table.Rows.Item(i)
            Dim info = infos.Item(i - 1)

            row.Item(1).Value = info.DisplayName
            row.Item(2).Value = info.Size
            row.Item(3).Value = info.Ups
            row.Item(4).Value = info.Downs
        Next
    End Sub
End Class

Public Class DocumentInfo
    Public Sub New(doc As PartDocument)
        Dim uom = doc.UnitsOfMeasure
        Dim def As SheetMetalComponentDefinition = doc.ComponentDefinition
        Dim flatPattern = def.FlatPattern

        For Each result As FlatBendResult In flatPattern.FlatBendResults
            If (result.IsOnBottomFace) Then Continue For
            If (result.IsDirectionUp) Then
                Ups += 1
            Else
                Downs += 1
            End If
        Next

        Dim width = uom.ConvertUnits(flatPattern.Width, UnitsTypeEnum.kDatabaseAngleUnits, UnitsTypeEnum.kDefaultDisplayAngleUnits)
        Dim length = uom.ConvertUnits(flatPattern.Length, UnitsTypeEnum.kDatabaseAngleUnits, UnitsTypeEnum.kDefaultDisplayAngleUnits)
        Size = String.Format("{0}x{1}", Math.Round(width, 5), Math.Round(length, 5))

        DisplayName = doc.DisplayName
    End Sub

    Public Property Ups As Integer = 0
    Public Property Downs As Integer = 0
    Public Property Size As String
    Public Property DisplayName As String
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Thanks A lot , it's working great , sorry for bothering you can the outputs be as custom property so I can added to existing table  , below is snap for the table  , thanks in advance.

AhmedshawkyXTZHN_2-1696673385424.png

 

0 Likes
Message 7 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
If it can be custom it I will be able to added to existing designs tables , thanks.
0 Likes
Message 8 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

@JelteDeJong  If it is not possible to make as custom property can we remove the part extension , thanks.

0 Likes
Message 9 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

@JelteDeJong Is it possible ?, thanks.

0 Likes
Message 10 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi @JelteDeJong  with reference to above conversation is it possible have the number of bending sides of sheet metal part , for example if there is 4 edges and only 2 edges have flanges it will mentioned that number of bends sides is 2, thanks.

 

0 Likes
Message 11 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi @Andrii_Humeniuk  ,

I saw one post similar to this one solved by you but couldn't find it didn't work to provide the required result , could you support me for that issue.

0 Likes
Message 12 of 14

JelteDeJong
Mentor
Mentor

This will fill the properties "ups" and "downs".

Public Sub main()

    Dim doc As DrawingDocument = ThisDoc.Document

    For Each refDoc As Document In doc.AllReferencedDocuments
        If (refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then Continue For
        If (refDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For

        Dim def As SheetMetalComponentDefinition = refDoc.ComponentDefinition

        If (Not def.HasFlatPattern) Then
            def.Unfold()
        End If

        Dim flatPattern = def.FlatPattern

        Dim ups = 0
        Dim downs = 0
        For Each result As FlatBendResult In flatPattern.FlatBendResults
            If (result.IsOnBottomFace) Then Continue For
            If (result.IsDirectionUp) Then
                ups += 1
            Else
                downs += 1
            End If
        Next

        SetCustomProperty(refDoc, "Ups", ups)
        SetCustomProperty(refDoc, "Downs", downs)
    Next
End Sub

Public Sub SetCustomProperty(doc As Document, name As String, value As String)
    Dim propSet = doc.PropertySets.Item("Inventor User Defined Properties")
    Try
        propSet.Item(name).Value = value
    Catch ex As Exception
        propSet.Add(value, name)
    End Try
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 13 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi @JelteDeJong  thanks for your quick response , sorry for the confusion , is it possible to get how many sides has bend for example the below part has 4 edges so all edges will have 4 bends .

AhmedshawkyXTZHN_0-1703653347729.png

 

0 Likes
Message 14 of 14

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi @JelteDeJong  is it possible to get the same , number of sides

0 Likes