How to use Inventor API DXF translator to handle spline replacement with arc approximation?

How to use Inventor API DXF translator to handle spline replacement with arc approximation?

jakubmLQNKE
Explorer Explorer
1,112 Views
7 Replies
Message 1 of 8

How to use Inventor API DXF translator to handle spline replacement with arc approximation?

jakubmLQNKE
Explorer
Explorer

Hello,

 

I'm facing problem connected with Invetor API and DXF translation - more specifically, splines replacement options during DXF export.

 

PROBLEM:

In Inventor 2023 there are 2 types of splines replacement:

jakubmLQNKE_0-1686726891632.png

I'm trying to pass some translation argument to DXF translator to handle Spline Replacement with Arc Approximation option.

 

In Inventor API documentation I see that there is argument SimplifySplines which allows me to Enable spline replacement by LINEAR segments. In the end there is no argument in documentation that make spline replacement by Tangent Arcs possible.

 

jakubmLQNKE_1-1686728531210.png

Ini file for DXF export contains property like SPLINE SIMPLIFICATION METHOD which informs about Linear or TangentArc simplification but I can’t find any option to pass it to translator.

 

QUESTION:

Is this possible to make DXF translation with Arc Approximation using Invenotr API. If yest, what translation argument should I use?

 

Thanks in advance.

Jakub

 

0 Likes
Accepted solutions (1)
1,113 Views
7 Replies
Replies (7)
Message 2 of 8

lmc.engineering
Advocate
Advocate

Hi

 

I generally create an ini file via 'Save Configuration' that contains the settings I want to export with, then use the following function to translate the ini to the correct format for the DataIO.WriteDataToFile method: 

Public Function Translate_ini(iniFullFileName As String) As String
        'Create stringbuilder to re-create ini
        Dim exportini As New System.Text.StringBuilder
        'Create a string that contains the invisible layers to append to the file
        Dim invisLayers = ""
        'Iterate through each line
        For Each line As String In System.IO.File.ReadAllLines(iniFullFileName)
            'Create a blank string to convert each line of the ini file into a readable output string
            Dim kernel = ""
            'Set the program compatibility
            If Line.Contains("AUTOCAD VERSION") Then
                'Set the year
                Dim year As Integer = Strings.Right(Line, 4)
                'Append the header file to the output
                exportini.Append("FLAT PATTERN DXF?AcadVersion=" & year)
            End If
            'Each layer contains an =, this differentiates between the comment lines which contain []
            If Line.Contains("=") Then
                Dim title = ""
                Dim header = ""
                Select Case True
                    'Create a title so we can loop through the different layer types rather than create a case for each
                    Case Line.Contains("Tangent")
                        header = "TANGENT"
                        title = "&TangentLayer"
                    Case Line.Contains("Bend") And Line.Contains("Front")
                        header = "BEND"
                        title = "&BendUpLayer"
                    Case Line.Contains("Bend") And Line.Contains("Back")
                        header = "BEND_DOWN"
                        title = "&BendDownLayer"
                    Case Line.Contains("Tool Centers") And Line.Contains("Front")
                        header = "TOOL_CENTER"
                        title = "&ToolCenterLayer"
                    Case Line.Contains("Tool Centers") And Line.Contains("Back")
                        header = "TOOL_CENTER_DOWN"
                        title = "&ToolCenterDownLayer"
                    Case Line.Contains("Arc Centers")
                        header = "ARC_CENTERS"
                        title = "&ArcCentersLayer"
                    Case Line.Contains("Outer Profile")
                        header = "OUTER_PROFILE"
                        title = "&OuterProfileLayer"
                    Case Line.Contains("Inner Profile")
                        header = "INTERIOR_PROFILES"
                        title = "&InteriorProfilesLayer"
                    Case Line.Contains("Feature Profile") And Line.Contains("Front")
                        header = "FEATURE_PROFILES"
                        title = "&FeatureProfilesLayer"
                    Case Line.Contains("Feature Profile") And Line.Contains("Back")
                        header = "FEATURE_PROFILES_DOWN"
                        title = "&FeatureProfilesDownLayer"
                    Case Line.Contains("Alternate Rep") And Line.Contains("Front")
                        header = "ALTREP_FRONT"
                        title = "&AltRepFrontLayer"
                    Case Line.Contains("Alternate Rep") And Line.Contains("Back")
                        header = "ALTREP_BACK"
                        title = "&AltRepBackLayer"
                    Case Line.Contains("Unconsumed Sketches")
                        header = "UNCONSUMED_SKETCHES"
                        title = "&UnconsumedSketchesLayer"
                    Case Line.Contains("Tangent Roll Lines")
                        header = "ROLL_TANGENT"
                        title = "&TangentRollLinesLayer"
                    Case Line.Contains("Roll Lines")
                        header = "ROLL"
                        title = "&RollLinesLayer"
                    Case Line.Contains("REBASE GEOMETRY")
                        If Line.Contains("Yes") Then
                            title = "&RebaseGeometry=True"
                        Else
                            title = "&RebaseGeometry=False"
                        End If
                    'Case Line.Contains("GROUP GEOMETRY")
                    '    If Line.Contains("Yes") Then
                    '        Title = "MergeProfilesIntoPolyline=True"
                    '    Else
                    '        Title = "MergeProfilesIntoPolyline=False"
                    '    End If
                    Case Line.Contains("REPLACE SPLINE")
                        If Line.Contains("Yes") Then
                            title = "&MergeProfilesIntoPolyline=True"
                        Else
                            title = "&MergeProfilesIntoPolyline=False"
                        End If
                    Case Line.Contains("SPLINE SIMPLIFICATION METHOD")
                        If Line.Contains("Linear") Then
                            title = "&SimplifySplines=True"
                        Else
                            title = "&SimplifySplines=False"
                        End If
                    Case Line.Contains("CHORD_TOLERANCE")
                        'Trim off identifyer
                        title = Strings.Right(Line, Len(Line) - InStrRev(Line, "="))
                        'replace syntax
                        title = Replace(title, ".", ",")
                        'trim off units
                        If title.Contains(" ") Then
                            title = "&SplineTolerance =" & Strings.Left(title, InStr(title, " ") - 1)
                        Else
                            title = "&SplineTolerance =" & title
                        End If

                End Select
                'Split the line into its individual components
                Dim splitArray As String() = Line.Split(";")
                Dim split As String
                'Iterate through each detail and convert it into a readable format
                If header = "" AndAlso title <> "" Then
                    kernel = title
                Else
                    For Each split In splitArray
                        'Differentiate visible layers from invisible layers
                        If Line.Contains("Visibility=ON") Then
                            'Go through each layer option and convert accordingly
                            Select Case True
                                Case split.Contains("=IV")
                                    'Write the 1st kernel of the tangent line
                                    kernel = title & "=IV_" & header
                                Case split.Contains("LinePattern")
                                    Select Case Strings.Right(split, Len(split) - InStrRev(split, "="))
                                        Case 28100 'continuous
                                            kernel = kernel & title & "LineType=37633"
                                        Case 28101 'dashed
                                            kernel = kernel & title & "LineType=37634"
                                        Case 28102 'dashed space
                                            kernel = kernel & title & "LineType=37641"
                                        Case 28103 'long dash dotted
                                            kernel = kernel & title & "LineType=37642"
                                        Case 28104 ' long dash double dot
                                            kernel = kernel & title & "LineType=37635"
                                        Case 28105 'long dash triple dot
                                            kernel = kernel & title & "LineType=37643"
                                        Case 28106 'dotted
                                            kernel = kernel & title & "LineType=37636"
                                        Case 28107 'chain
                                            kernel = kernel & title & "LineType=37644"
                                        Case 28108 'double dash chain
                                            kernel = kernel & title & "LineType=37637"
                                        Case 28109 'dash double dot
                                            kernel = kernel & title & "LineType=37645"
                                        Case 28110 ' dash dot
                                            kernel = kernel & title & "LineType=37638"
                                        Case 28111 'double dash dot
                                            kernel = kernel & title & "LineType=37646"
                                        Case 28112 'double dash double dot
                                            kernel = kernel & title & "LineType=37639"
                                        Case 28113 'dash triple dot
                                            kernel = kernel & title & "LineType=37647"
                                        Case 28114 'double dash triple dot
                                            kernel = kernel & title & "LineType=37640"
                                    End Select
                                Case split.Contains("LineWeight")
                                    'Lineweights have the same syntax so I've tagged it onto the converted identifyer
                                    split = Replace(split, ";", "")
                                    kernel = kernel & title & Replace(split, ".", ",")
                                Case split.Contains("Color")
                                    'same as lineweights
                                    split = Replace(split, ";", "")
                                    kernel = kernel & title & Replace(split, ",", ";")
                                Case split = ""
                                    'the last split returns nothing so don't include anything in the kernel
                                Case Else
                                    'Add flat pattern geometry options 
                                    kernel = kernel & title
                            End Select
                        ElseIf Not Line.Contains("[") AndAlso header <> "" Then
                            'for invisible layers, compile a list and tag on at the end
                            If invisLayers = "" Then
                                invisLayers = "IV_" & header
                            Else
                                invisLayers = invisLayers & ";IV_" & header
                            End If
                            Exit For
                        End If
                    Next
                End If
                'add the compiled kernel before moving to the next line
                If kernel <> "" Then exportini.Append(kernel)
            End If
        Next
        'After all the lines are read, tack on the invisible layers
        If invisLayers <> "" Then exportini.Append("&InvisibleLayers=" & invisLayers)
        'Return the string as the output for the dxf
        Return exportini.ToString
    End Function

Used as below:

Public Sub PublishDocumentDXF(doc As Document, iniFullFileName As String, dxfFullFileName As String)
	Dim sOutDXF As String
	'translate ini file for export out
	Try
		sOutDXF = Translate_ini(iniFullFileName)
	Catch ex As Exception
		sOutDXF = "FLAT PATTERN DXF?AcadVersion=2010&OuterProfileLayer=Outer"
	End Try

	Dim oDataIO As Inventor.DataIO
	oDataIO = doc.ComponentDefinition.DataIO

	Try
		oDataIO.WriteDataToFile(sOutDXF, dxfFullFileName)
	Catch ex As Exception
		MessageBox.Show("Failed to export the following DXF File: " & vbCrLf & dxfFullFileName)
	End Try
End Sub

Hopefully of some use.

Message 3 of 8

jakubmLQNKE
Explorer
Explorer

Hi,

Thanks for replay. Are you sure that it handles TangentArt spline replacement? 
That code is crucial:

jakubmLQNKE_0-1686750710600.png

I try this and if SPLINE SIMPLIFICATION METHOD is set to "TangentArc" and not "Linear" then argument SimplifySplines = FALSE. As a result any type of spline replacement doesn't occur.

What do You thing about that?

 

 

0 Likes
Message 4 of 8

lmc.engineering
Advocate
Advocate

Right, I see the issue now. My apologies. 

I'm on Inventor 2022 so can't see this new feature, however, you could create the ini file with your desired settings and read through it ( I just put to debugger output, as below), then you should be able to see what is missing in my previous function and add it in? Guessing it would have the line "Arc Approximation = true" perhaps. I'd happily try myself but I lack the newer Inventor version..

Public Shared Sub ReadINI(iniffn As String)
	For Each line As String In System.IO.File.ReadAllLines(iniffn)
		Debug.WriteLine(Line)
	Next
End Sub

 Regards

0 Likes
Message 5 of 8

lmc.engineering
Advocate
Advocate
Accepted solution

Briefly looking at the DataIO.WriteDataToFile as per link below, I can see down the bottom the option for 'SimplifyAsTangentArcs' as boolean:


https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=DataIO_WriteDataToFile

So it might look like this:

Case Line.Contains("SPLINE SIMPLIFICATION METHOD")
                        If Line.Contains("Linear") Then
                            title = "&SimplifyAsTangentArcs=False"
                        Else
                            title = "&SimplifyAsTangentArcs=True"
                        End If

 

 

Message 6 of 8

jakubmLQNKE
Explorer
Explorer

Briliant. That's exacly what I was looking for 🙂 Inventor 2023 API doesn't contain information about attribute SimplifyAsTangentArcs but I check it on 2023 version and it works properly.

 

Thak you for Your help.

0 Likes
Message 7 of 8

niels.debaets
Participant
Participant

This looks like this can be usefull for what I'm trying, too. Is this code ready to set up, or do I need to add some layers between these brackets?

Dim invisLayers = ""
        'Iterate through each line

 Furthermore, do I need to set anything correct at the kernel brackets or does this need to be blank?

Dim kernel = ""
            'Set the program compatibility

If I need to add anything, can share your code as it is right now so I know what to adapt?

 

0 Likes
Message 8 of 8

niels.debaets
Participant
Participant

Hi @lmc.engineering, This seems to work (partly) to export a DXF using an ini file. The visible/invisible layers are correct, but colours don't match the ini file. I tried modifying the ini file, checked the value of the ini file and then exported the DXF using the "save copy as" command in flat pattern mode to check if the ini was usable, which it was, but the iLogic rule from above seems not to be able to process the colours well. Whatever color I set in the ini file, they remain the same when I export the DXF using the iLogic rule.
Restarting Inventor was no solution, I thought the ini was loaded in cache for some reason but that seems not to be the case.

0 Likes