09-28-2020
12:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-28-2020
12:09 PM
I know it's been a while, but this is an ammendment to the code that I had originally posted so it will be relevant to anyone who will use this in the future.
I've added functionality for converting linetypes as well as correcting an issue with legacy bend lines causing issue with the linetype.
Function Translate_ini(ini) As String
'Create stringbuilder to re-create ini
Dim exportini As New 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(ini)
'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