Help with iLogic: Projecting Bend Lines from Unfolded Sheet Metal

Help with iLogic: Projecting Bend Lines from Unfolded Sheet Metal

vijay_balakrishnanEA333
Explorer Explorer
205 Views
5 Replies
Message 1 of 6

Help with iLogic: Projecting Bend Lines from Unfolded Sheet Metal

vijay_balakrishnanEA333
Explorer
Explorer

Hi everyone,

I'm working with a folded sheet metal part in Autodesk Inventor.

My Need:
I manually unfold the model and then run an iLogic rule that automatically creates a sketch on the top surface of the unfolded face.

The goal is to identify the bend lines (i.e., the internal fold regions between two adjacent faces) and project only those lines into the sketch.

I'm looking for help or guidance on how to accurately detect these bend line areas and project just those into the sketch using iLogic.

I've attached an image 
Any tips, sample code, or suggestions would be greatly appreciated!

Thanks in advance!

vijay_balakrishnanEA333_0-1753250943042.png

 

0 Likes
206 Views
5 Replies
Replies (5)
Message 2 of 6

vijay_balakrishnanEA333
Explorer
Explorer

"I tried this iLogic code, but it's not working. Please help me solve the problem. The result shown in the attached image only projects the outer edges, but I want to project only the fold line areas."

vijay_balakrishnanEA333_0-1753251823315.png

 



Sub Main()

    ' Setup
    Dim oDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

    ' === STEP 1: Find the top unfolded flat face ===
    Dim topFace As Face = Nothing
    Dim maxArea As Double = 0

    For Each oFace As Face In oCompDef.SurfaceBodies(1).Faces
        If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
            Dim area As Double = oFace.Evaluator.Area
            If area > maxArea Then
                maxArea = area
                topFace = oFace
            End If
        End If
    Next

    If topFace Is Nothing Then
        MessageBox.Show("No flat top face found. Please unfold the part first.")
        Return
    End If

    ' === STEP 2: Create sketch on top face ===
    Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(topFace)

    ' === STEP 3: Loop through edges and detect true bend lines ===
    For Each oEdge As Edge In oCompDef.SurfaceBodies(1).Edges

        If oEdge.GeometryType = CurveTypeEnum.kLineSegmentCurve Then

            If oEdge.Faces.Count = 2 Then

                Dim face1 As Face = oEdge.Faces(1)
                Dim face2 As Face = oEdge.Faces(2)

                ' Both must be planar
                If face1.SurfaceType = SurfaceTypeEnum.kPlaneSurface And face2.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

                    ' Exclude edge if it lies between top face and another (outer edge)
                    If face1.Equals(topFace) Or face2.Equals(topFace) Then
                        Continue For
                    End If

                    ' Check angle between faces
                    Dim normal1 As UnitVector = GetFaceNormal(face1)
                    Dim normal2 As UnitVector = GetFaceNormal(face2)

                    Dim dot As Double = normal1.DotProduct(normal2)

                    If Math.Abs(dot) < 0.98 Then
                        ' True bend line — project it
                        oSketch.AddByProjectingEntity(oEdge)
                    End If

                End If
            End If
        End If
    Next

    oSketch.Name = "TrueBendLines"
    MessageBox.Show("Bend lines (excluding outer edges) projected to sketch.")

End Sub

' === Helper: Safe face normal evaluator ===
Function GetFaceNormal(oFace As Face) As UnitVector
    Dim pt As Point = oFace.PointOnFace
    Dim oPointArr(2) As Double
    oPointArr(0) = pt.X
    oPointArr(1) = pt.Y
    oPointArr(2) = pt.Z

    Dim oNormalArr(2) As Double
    oFace.Evaluator.GetNormalAtPoint(oPointArr, oNormalArr)

    Dim oVec As Vector = ThisApplication.TransientGeometry.CreateVector(oNormalArr(0), oNormalArr(1), oNormalArr(2))
    Return oVec.AsUnitVector
End Function



0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

HI @vijay_balakrishnanEA333.  I see that you are aware of, and using the 'SheetMetalComponentDefinition', but it looks to me like you need to venture down into the actual 'FlatPattern' of the sheet metal part.  To get there, we usually first check the SheetMetalComponentDefinition.HasFlatPattern property value, then if that is True, we know that we will get a value from the SheetMetalComponentDefinition.FlatPattern property.  Then, we can use the FlatPattern.FlatBendResults property to iterate though each of its FlatBendResult objects.  That object has two properties that may be of interest to you.  One is the FlatBendResult.Edge property, the other is the FlatBendResult.Bend.  But you may also be interested in checking the FlatBendResult.IsDirectionUp or FlatBendResult.IsOnBottomFace properties first, for added information.  When going the 'Bend' route, you can use the Bend.FrontFaces & Bend.BackFaces properties.  Since a part can be in any orientation, who's to say which is the front or back faces of it, so some experimentation would likely be needed to determine which of those to use in your specific situation.  Then you can iterate through those faces, and project the edges of each face to the sketch.

As for the sketch itself, you could use the FlatPattern.TopFace, or FlatPattern.BottomFace, or FlatPattern.BaseFace (the one chosen to be stationary when creating a flat pattern).  No need to find the face with the largest area.  In most situations, both the top and bottom faces of a flat pattern will have exactly the same area. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

vijay_balakrishnanEA333
Explorer
Explorer

Hi @WCrihfield 

Thanks for the input! Just to clarify — I’m not using the FlatPattern. I’m working in the folded model, even after unfolding it manually.

My goal is to detect the bend (fold) lines directly from the folded part and project them onto a sketch. So I’m filtering short, internal edges on the selected face — without relying on FlatPattern.FlatBendResults.

Appreciate your help!

Best,
Vijay

Message 5 of 6

WCrihfield
Mentor
Mentor

OK.  Well the regular 'Bends' collection can be reached from the SheetMetalComponentDefinition.Bends property, so you could try iterating though those instead.  And if you used 'UnfoldFeature' or 'RefoldFeature' to flatten the folded part without using FlatPattern, and want to use those, they both have a Bends property also.  When iterating through the Faces of each Bend, then iterating through the Edges of each Face, it may be difficult to avoid projecting the 'side' edges and only project the 'bend' edges though.  One additional thing you may be able to take advantage of to help with that is the Face.TangentiallyConnectedFaces property.  I can't remember at this moment, but it may be possible for the FaceCollection which that property returns to include faces that are not directly touching the current Face.

So, assuming there is just one Face in the Bend.Faces collection, that one Face will likely have at least 4 Edges.  Two of them are likely between that face and the 'sides' of the part, while the other two are between that bend and tangentially connected faces, which are most likely the only ones you want (but I am not sure, since I have no idea what you are using the sketch for.  If that is the case, then when iterating each Edge of the bend face, you can check if the 'other' face of each Edge (not the bend Face) is tangentially connected to the bend face, by seeing if it is in the collection of BendFace.TangentiallyConnectedFaces.  If it is, then you have a match, and will want to project that one.  Just some additional thoughts.

Edit:  On second thought, if the part is flattened by an UnfoldFeature, I am not sure if the TangentiallyConnectedFaces idea would work, so that may also require some trial & error testing.  That's the best way to learn anyways...sticks better.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

CGBenner
Community Manager
Community Manager

@vijay_balakrishnanEA333 

 

Did the information provided answer your question? If so, please use Accept Solution so that others may find this in the future. Thank you very much!

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

0 Likes