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.