Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: How to correctly create a complexstring from a perimeter

Phenom
Phenom

Tushar, that is really excellent.

 

Unfortunately, I immediately ran into another issue. Attached is another DXF, saved straight from Solid Edge, that appears to have the arc order mixed up... I have also attached the .psm (from ST7). There is a spline in the model that is turned into two lines upon flat pattern save, and I think when this happens the order of the drawing elements is not maintained. This means now I'll have to reorder the elements before creating the complexstring. Not fun. Smiley Sad

 

(PS- DXF file extension once more changed to .docx to be able to attach)

-Dylan Gondyke

Re: How to correctly create a complexstring from a perimeter

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Dylan, I was not able to open the PSM file you attached since it not compatible with my ST6

Is it created using a academic version ?

 

I could verify the elements are indeed not in proper order.

So, the next two tasks are:

1. Arranging the elements in a proper sequence.

2. Detecting and then fixing the arcs when they are connected to other arcs and not just lines.

 

These are in fact task lists for Siemens if any one from the Solid Edge dev team is listening.

For now,

#1 - I think can handle this.

#2 - Could be a problem if there are two "problem arcs" end-to-end. In that case it can be tricky.

Is it fine to assume that all arcs of the DXF are less than 90 deg. Or do you have a case where there are arcs greater than 90. Let me know. #2 can also be solved with this assuption.

 

What do you with the ComplexString after it is created properly ?

 

Re: How to correctly create a complexstring from a perimeter

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

In one of your posts, did Susan indicate DXF was added as a legal extension ?

Highlighted

Re: How to correctly create a complexstring from a perimeter

Phenom
Phenom

I posted again in the Community Suggestions and pinged Susan about extensions. I think that the Developer forums have a different allowable file extension list than the rest of the Solid Edge forums!

 

I am almost done cobbling together a solution, which puts all elements in the Outer Loop in an array and then sorts it into another array based on common start/end points. This works for arcs to arcs, splines to arcs, etc, and is correctly handling the arc reversal where necessary through all possible arc angles. I'll post the finished, cleaned up code when it works with every test case I can throw at it.

 

This started out as attempting to calculate the area of a flat pattern, (which requires a complexstring of the perimeter), which was much faster to do by cycling through all of my automatically created DXF's in each project folder rather than opening each individual psm file. 

-Dylan Gondyke

Re: How to correctly create a complexstring from a perimeter

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Thanks for mentioning your idea about using arrays to sort the entities.

I am too working on sorting based on end-poiint conectivity, but now you have thrown in splines too, so I must revisit my logic and code done so far.

 

For curves, I believe it needs to be evaluated.

Or do the nodes provide the endpoints data ?

 

As for the final code, I am watching this space Dylan.

 

~Tushar

Re: How to correctly create a complexstring from a perimeter

Phenom
Phenom
Simplify Bsplines in DXF options (default selection) eliminates having to deal with curves altogether.

I am still having trouble cycling through the radii and correctly changing their orientation.....I have not forgotten about this issue!
-Dylan Gondyke

Re: How to correctly create a complexstring from a perimeter

Phenom
Phenom

I never got this working for more than simple profiles. Because there is no consistency in 'direction' over complex elements that cannot easily be flipped, it becomes impossible to chain it all together startpoint to endpoint. A better way would be applying connect relationships between each item, which eliminates the need to flip elements entirely...but using AddKeyPoint necessitates you specify start/end points as igLineStart, igEllipseArcStart, etc.., which means a massive amount of code to handle all possible branching based on the two elements being joined.

 

Another good option is AddAutoConstraints, but this method contains 19 parameters and has no examples in the SDK. 

 

 

 

Just for example, below is some of what I wrote that sorts simple profiles that are fed into the function as an array of drawing objects, but it takes an unacceptable amount of time with profiles with more elements, and it only deals with flipping problems with arcs.

 

 

Public Function FixComplexString(objarray() As Object)
        'Takes an array of elements and sorts them by endpoints, corrects geometry continuity issues.
        Const ConnectTolerance = 0.000001
        Dim SortedObjArray(objarray.Count - 1, 5) As Object  '0: object, 1: original index, 2: StartX, 3: StartY, 4: EndX, 5: EndY 
        Dim dblcircsize As Double = 0.001
        Dim intDuplicateCheck As Integer = 0



        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        'Loop through the array and rearrange everything into new array by checking start/end points.

        'Need to choose a starting element that is NOT an arc, in order to preserve correct loop direction of elements we cannot reverse
        For i As Integer = 0 To objarray.Count - 1 Step 1
            If Not TypeOf objarray(i) Is SolidEdgeFrameworkSupport.Arc2d Then
                SortedObjArray(0, 0) = objarray(0)
                SortedObjArray(0, 1) = 0
                Exit For
            End If
        Next

        'If no straight line elements exist and loop is entirely arcs, simply choose the first one
        If SortedObjArray(0, 0) Is Nothing Then
            SortedObjArray(0, 0) = objarray(0)
            SortedObjArray(0, 1) = 0
        End If

        Try
            For i As Integer = 0 To objarray.Count - 2 Step 1 'Loop through base elements minus one, because last element does not need a 'match'

                Dim CurrentSX, CurrentSY As Double : SortedObjArray(i, 0).GetStartPoint(CurrentSX, CurrentSY)
                Dim CurrentEX, CurrentEY As Double : SortedObjArray(i, 0).GetEndPoint(CurrentEX, CurrentEY)

                'If only one element currently exists in the sorted array, set the duplicatecheck index to 0.
                If i = 0 Then
                    intDuplicateCheck = 0
                Else
                    intDuplicateCheck = SortedObjArray(i - 1, 1)
                End If

                For j As Integer = 0 To objarray.Count - 1 Step 1 'Only loop through remaining elements in the original array that have not been sorted.
                    'Avoid finding duplicate or already sorted elements based on their original array index. This looks at the last two sorted items.
                    If j <> SortedObjArray(i, 1) And j <> intDuplicateCheck Then
                        Dim SearchSX, SearchSY As Double : objarray(j).GetStartPoint(SearchSX, SearchSY)
                        Dim SearchEX, SearchEY As Double : objarray(j).GetEndPoint(SearchEX, SearchEY)

                        If Math.Abs(CurrentEX - SearchSX) < ConnectTolerance And Math.Abs(CurrentEY - SearchSY) < ConnectTolerance Then 'Found a startpoint matching this endpoint!
                            SortedObjArray(i + 1, 0) = objarray(j)
                            SortedObjArray(i + 1, 1) = j
                            SortedObjArray(i + 1, 2) = SearchSX
                            SortedObjArray(i + 1, 3) = SearchSY
                            SortedObjArray(i + 1, 4) = SearchEX
                            SortedObjArray(i + 1, 5) = SearchEY
                            Exit For
                        ElseIf Math.Abs(CurrentEX - SearchEX) < ConnectTolerance And Math.Abs(CurrentEY - SearchEY) < ConnectTolerance Then 'Found an endpoint matching this endpoint!
                            SortedObjArray(i + 1, 0) = objarray(j)
                            SortedObjArray(i + 1, 1) = j
                            SortedObjArray(i + 1, 2) = SearchSX
                            SortedObjArray(i + 1, 3) = SearchSY
                            SortedObjArray(i + 1, 4) = SearchEX
                            SortedObjArray(i + 1, 5) = SearchEY
                            Exit For
                        ElseIf Math.Abs(CurrentSX - SearchSX) < ConnectTolerance And Math.Abs(CurrentSY - SearchSY) < ConnectTolerance Then 'Found a startpoint matching this startpoint!
                            SortedObjArray(i + 1, 0) = objarray(j)
                            SortedObjArray(i + 1, 1) = j
                            SortedObjArray(i + 1, 2) = SearchSX
                            SortedObjArray(i + 1, 3) = SearchSY
                            SortedObjArray(i + 1, 4) = SearchEX
                            SortedObjArray(i + 1, 5) = SearchEY
                            Exit For
                        ElseIf Math.Abs(CurrentSX - SearchEX) < ConnectTolerance And Math.Abs(CurrentSY - SearchEY) < ConnectTolerance Then 'Found an endpoint matching this startpoint!
                            SortedObjArray(i + 1, 0) = objarray(j)
                            SortedObjArray(i + 1, 1) = j
                            SortedObjArray(i + 1, 2) = SearchSX
                            SortedObjArray(i + 1, 3) = SearchSY
                            SortedObjArray(i + 1, 4) = SearchEX
                            SortedObjArray(i + 1, 5) = SearchEY
                            Exit For
                        End If
                    End If
                Next
            Next
        Catch ex As Exception
            MsgBox("Problem creating a sorted array of Outer Loop Elements!" & vbCrLf & ex.Message)
        End Try

        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        '-------------------------------------------------------------------------------------------------------------------------------------------------------


        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        'Loop through the new array and fix any arcs as necessary
        Try
            ReDim objarray(objarray.Count - 1) 'Clear original array to put newly sorted and fixed elements back in.
            objarray(0) = SortedObjArray(0, 0)

            For i As Integer = 1 To objarray.Count - 1 'Ignore first element as we are assuming it is already pointed in the correct direction from the above
                'Now compare end point of element to end point of previous element
                If TypeOf SortedObjArray(i, 0) Is SolidEdgeFrameworkSupport.Arc2d Then
                    If Math.Abs(SortedObjArray(i, 4) - SortedObjArray(i - 1, 4)) < ConnectTolerance And Math.Abs(SortedObjArray(i, 5) - SortedObjArray(i - 1, 5)) < ConnectTolerance Then
                        'We have found an element with mixed endpoints.
                        SortedObjArray(i, 0).SetStartPoint((SortedObjArray(i, 2) + SortedObjArray(i, 4)) / 2, (SortedObjArray(i, 3) + SortedObjArray(i, 5)) / 2)
                        SortedObjArray(i, 0).SetEndPoint(SortedObjArray(i, 2), SortedObjArray(i, 3))
                        SortedObjArray(i, 0).SetStartPoint(SortedObjArray(i, 4), SortedObjArray(i, 5))

                        'Flip arc direction after flipping start/end points
                        If SortedObjArray(i, 0).Orientation = SolidEdgeFrameworkSupport.Geom2dOrientationConstants.igGeom2dOrientCounterClockwise Then
                            SortedObjArray(i, 0).Orientation = SolidEdgeFrameworkSupport.Geom2dOrientationConstants.igGeom2dOrientClockwise
                        Else
                            SortedObjArray(i, 0).Orientation = SolidEdgeFrameworkSupport.Geom2dOrientationConstants.igGeom2dOrientCounterClockwise
                        End If
                    End If
                End If

                'Return object to original array in new position
                objarray(i) = SortedObjArray(i, 0)
            Next


        Catch ex As Exception
            MsgBox("Problem repairing endpoints of Outer Loop Elements!" & vbCrLf & ex.Message)
        End Try
        '-------------------------------------------------------------------------------------------------------------------------------------------------------
        '-------------------------------------------------------------------------------------------------------------------------------------------------------

        Return objarray
    End Function

 

 

 

-Dylan Gondyke