Managing orientation of flat layouts with iLogic - Methods?

Managing orientation of flat layouts with iLogic - Methods?

llorden4
Collaborator Collaborator
1,020 Views
7 Replies
Message 1 of 8

Managing orientation of flat layouts with iLogic - Methods?

llorden4
Collaborator
Collaborator

I'm looking for ways to automate the management of flat layouts with iLogic and can't seem to find solutions and hoping perhaps you might have some ideas or experience to share.  Here are my challenges...

 

I have iLogic creating bent sheet metal parts for a variety of install conditions.  This often creates odd shapes or tapered legs.  In the flat layout, I grab the extents of the flat pattern to determine material requirements.  Inventor appears to be quite random on how it chooses to unfold a part, thus using automation to determine orientation or a specific edge seems impossible.

 

[Random unfold example 1:]  Part is rotated and aligned with a tapered edge.

llorden4_0-1708597060047.png   

llorden4_2-1708597256846.png

 

[Random unfold example 2:]  Part is not rotated and is aligned with a non-tapered edge

llorden4_3-1708597374191.png

llorden4_4-1708597411322.png

 

How can I overcome this challenge of figuring out what random position Inventor decided to place my unfolded part in, from an iLogic point of view.  Once I can figure out what the orientation is, I need to set it to an orientation "I" want, which is typically some alignment to the World UCS I had defined in the part model.

 

I have an Idea Submission to add such a feature at this link, would appreciate your vote.

https://forums.autodesk.com/t5/inventor-ideas/flat-pattern-orientation-by-ucs-plane/idi-p/8899409

 

The reason I want to manage orientation is it has a direct impact on extent results, which I use to manage automation of material order requirements as well as part description generators.

 

[Skewed orientation extent results]

llorden4_7-1708598043603.png

[Levelled orientation extent results]

llorden4_8-1708598130929.png

 

Extent results are critical to the success of operations and that's "the" biggest challenge I'm facing at present.  Very interested in any solution paths anyone might have to offer on tackling these issues.

 

 

 

 

 

 

Autodesk Inventor Certified Professional
0 Likes
1,021 Views
7 Replies
Replies (7)
Message 2 of 8

mat_hijs
Collaborator
Collaborator

I'm not sure if this will help you but at least the orientation is not random according to this link: How to predict the Flat Pattern orientation in Inventor (autodesk.com)

0 Likes
Message 3 of 8

llorden4
Collaborator
Collaborator

That's helpful, but even those rules aren't being followed.  Here's a screenshot of the image I used in that idea link in my OP and it's not following any of those listed rules.

 

llorden4_0-1708683745482.png

 

Autodesk Inventor Certified Professional
0 Likes
Message 4 of 8

iLimbani
Contributor
Contributor

Hi @llorden4,

Please find the below iLogic code for the solution. The basic idea of the solution is to use inventor's Minimum rangebox read only property values (would be same in any orientation) and comparing them with the sheet metal extentents property to identify the problem. if not same then it will create a outside lines on top face of the flat layout and find parallel lines. Depends on parallel lines count condition follows as shown in iLogic.

Please refer to my post here,
Re: Is there a need for optimization in the algorithm used by Inventor for Sheet Metal Flat Pattern ...

Let me know if you have more questions

Public Sub SMORIENTATION(ByRef oDDef As SheetMetalComponentDefinition, ByRef oDoc As Document)

    If Not oDDef.HasFlatPattern Then
        oDDef.Unfold()
    Else
        oDDef.FlatPattern.Edit()
    End If
	
    Dim length As Double = 0
    Dim height As Double = 0
    Dim extents_length As Double = 0
    Dim extents_height As Double = 0
	
	'getting length and height from flat pattern created by inventor
	extents_length = Round(SheetMetal.FlatExtentsLength, 0)
	extents_height = Round(SheetMetal.FlatExtentsWidth, 0)

	'getting length and height from Minimum RangeBox of flat pattern created by inventor
	Dim oBox As OrientedBox = oDDef.FlatPattern.OrientedMinimumRangeBox
    length = Round(oDoc.UnitsOfMeasure.ConvertUnits(oBox.DirectionOne.Length, "cm", oDoc.UnitsOfMeasure.LengthUnits), 0)
    height = Round(oDoc.UnitsOfMeasure.ConvertUnits(oBox.DirectionTwo.Length, "cm", oDoc.UnitsOfMeasure.LengthUnits), 0)
	
'	MessageBox.Show(length, "length")
'	MessageBox.Show(height, "height")
'	MessageBox.Show(extents_length, "extents_length")
'	MessageBox.Show(extents_height, "extents_height")
   Try
	'comparing parameters
	If Not ( (extents_length = length Or extents_length = height) AndAlso (extents_height = length Or extents_height = height) AndAlso (length > height)) Then 
'		MessageBox.Show("Message", "Title")

'     Delete existing flat pattern If it exists
    If oDDef.HasFlatPattern Then
        oDDef.FlatPattern.Delete()
    End If

' Unfold Or start editing flat pattern
    If Not oDDef.HasFlatPattern Then
        oDDef.Unfold()
    Else
        oDDef.FlatPattern.Edit()
    End If

    ' Get active flat pattern and its top face
    Dim oFlatPattern As FlatPattern = ThisApplication.ActiveEditObject
    Dim oFace As Face = oFlatPattern.TopFace

    ' Add sketch to the flat pattern's top face
    Dim oSketch As PlanarSketch = oFlatPattern.Sketches.Add(oFace, True)

    ' Get all the edges in the flat pattern
    Dim oEdges As Edges = oFlatPattern.TopFace.Edges

    ' Create a dictionary to store the projected entities for each edge
    Dim projectedEntities As New Dictionary(Of Edge, SketchEntity)

    ' Project each edge onto the sketch once and store the result in the dictionary
    For Each oEdge As Edge In oEdges
        projectedEntities.Add(oEdge, oSketch.AddByProjectingEntity(oEdge))
    Next

    ' Create a list to store line lengths and a corresponding list to store the lines
    Dim lineLengths As New List(Of Double)
    Dim lines As New List(Of SketchLine)

    ' Iterate through the projected entities to get their lengths
    For Each entity As SketchEntity In projectedEntities.Values
        If TypeOf entity Is SketchLine Then
            Dim line As SketchLine = DirectCast(entity, SketchLine)
            lineLengths.Add(line.Length)
            lines.Add(line)
        End If
    Next

    ' Sort the line lengths in descending order and get the indices of the sorted lengths
    Dim sortedIndices As List(Of Integer) = lineLengths.Select(Function(x, i) New With {Key .Value = x, Key .Index = i}).OrderByDescending(Function(x) x.Value).Select(Function(x) x.Index).ToList()

    ' Create a list to store the top 4 lines
    Dim topLines As New List(Of SketchLine)

    ' Get the top 4 lines
    Dim numLinesToConsider As Integer = Math.Min(4, lines.Count)
    For i As Integer = 0 To numLinesToConsider - 1
        topLines.Add(lines(sortedIndices(i)))
    Next

    ' Now you have the top 4 lines in the topLines list
    ' You can proceed with checking for parallelism among them
    Dim foundParallelLines As Boolean = False
    Dim parallelLines As New List(Of SketchLine)

    ' Create a dictionary to store the angles and slopes of each top line
    Dim lineAngles As New Dictionary(Of SketchLine, Double)
    Dim lineSlopes As New Dictionary(Of SketchLine, Double)

    ' Calculate the angles and slopes of the top lines
    For Each line As SketchLine In topLines
        ' Calculate the angle of the line
        Dim startPoint As Point2d = Line.Geometry.StartPoint
        Dim endPoint As Point2d = Line.Geometry.EndPoint
        Dim angle As Double = Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X)

        ' Store the angle and slope of the line
        lineAngles.Add(Line, angle)
        lineSlopes.Add(Line, Math.Tan(angle))
    Next

    For i As Integer = 0 To topLines.Count - 1
        For j As Integer = i + 1 To topLines.Count - 1
            Dim line1 As SketchLine = topLines(i)
            Dim line2 As SketchLine = topLines(j)

            ' Get the slopes of the lines from the dictionary
            Dim slope1 As Double = lineSlopes(line1)
            Dim slope2 As Double = lineSlopes(line2)

            Dim slopeThreshold As Double = 0.01
            If Math.Abs(slope1 - slope2) < slopeThreshold Then
                ' Store the edges corresponding to parallel lines
                parallelLines.Add(line1)
                parallelLines.Add(line2)
                foundParallelLines = True
                Exit For ' Exit the inner loop if parallel lines are found
            End If
        Next
        If foundParallelLines Then Exit For ' Exit the outer loop if parallel lines are found
    Next

    ' Declare variables to hold the lines and edges associated with the parallel lines
    Dim edge1 As Edge = Nothing
    Dim edgemax As Edge = Nothing

    For Each oEdge As Edge In oFlatPattern.TopFace.Edges
        Dim projectedEntity As SketchEntity = projectedEntities(oEdge)
        If TypeOf projectedEntity Is SketchLine Then
            Dim line As SketchLine = DirectCast(projectedEntity, SketchLine)

            If foundParallelLines = True Then
                If line.Length = parallelLines(0).Length Then
                    edge1 = oEdge
                End If
            End If

            If line.Length = lineLengths(sortedIndices(0)) Then
                edgemax = oEdge
            End If

        End If
    Next

    If parallelLines.Count = 0 Then
        oDDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation.AlignmentAxis = edgemax
    End If

    If parallelLines.Count > 0 Then
        If lineLengths(sortedIndices(0)) = lineLengths(sortedIndices(1)) AndAlso lineLengths(sortedIndices(0)) = parallelLines(0).Length AndAlso lineLengths(sortedIndices(0)) = parallelLines(1).Length Then
            oDDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation.AlignmentAxis = edge1
        Else
            oDDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation.AlignmentAxis = edge1
            If Math.Abs(lineLengths(sortedIndices(2)) - parallelLines(0).Length) < 0.01 Then
                Dim rotationAngle As Double = Math.PI / 2
                oDDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation.AlignmentRotation().Value = rotationAngle
            End If
        End If
    End If
	
	oSketch.Delete()
    oDDef.FlatPattern.ExitEdit()
	
	        ' Clear lists
        lineLengths.Clear()
        lines.Clear()
        topLines.Clear()
        parallelLines.Clear()

        ' Set dictionaries to Nothing
        projectedEntities = Nothing
        lineAngles = Nothing
        lineSlopes = Nothing
	
End If
Catch ex As Exception
        ' Handle exceptions gracefully
        MessageBox.Show("An error occurred: " & ex.Message, "Error")
 End Try
End Sub 

 

0 Likes
Message 5 of 8

_dscholtes_
Advocate
Advocate

@iLimbaniI once created a script to orient parts along the origin's axes using the 'largest face, longest edge' method taking into account perpendicular, parallel or tapered edges. Instead of projecting edges, I used the edges of the top face and created vectors of them. Using the vector properties '.IsPerpendicularTo' and '.IsParallelTo' saves you calculating angles and slopes. And calculating the 'mirror axis' / alignment axis for a tapered part is as simpel as adding the two vectors.

0 Likes
Message 6 of 8

llorden4
Collaborator
Collaborator

Thanks, this does a better job at defining a factory edge for nesting than the default Inventor flat layout but isn't putting me on the path towards the goals I've outlined.

Autodesk Inventor Certified Professional
0 Likes
Message 7 of 8

iLimbani
Contributor
Contributor

can you please share the iLogic code containing vector defining. So that I can avoid calculation in my rule.
Thank you @_dscholtes_ 

0 Likes
Message 8 of 8

iLimbani
Contributor
Contributor

Hi @llorden4,

I believe no one is sure till now about concept used by inventor to make a flat pattern. Please see my post here . Is there a need for optimization in the algorithm used by Inventor for Sheet Metal Flat Pattern view...

@mat_hijs has attached link in answer, which I believe that's what Inventor wanted us to know about it.

To get accurate extent result,
1] we are bound to use ilogic shared by me to make orientation correctly and then extract Extent result

OR

2] we can use iLogic which spits minimum range box values (it would be same in any flat pattern orientation). you can find that iLogic in my post (Link is given in starting).

0 Likes