06-11-2018
09:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-11-2018
09:14 AM
A bit of a thread resurrection, but I came across this again in my projects and finally decided to bite the bullet and create a translator. I wrote it in vb.net so it shouldn't take much effort to translate it into iLogic.
It's a pretty basic function. You pass it the .ini text in a string and it will spit back the translated sOut.
I've run a few tests with it and it seems to work, but let me know if you have issues.
In your main sub call this:
Dim sOut As String sOut = Translate_ini(***your ini string***) oDataIO.WriteDataToFile(sOut, ****Location you wish to save to***)
And reference it to this:
Function Translate_ini(ByVal ini) 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 As String = ""
'Iterate through each line
For Each line As String In System.IO.File.ReadLines(ini)
'Create a blank string to convert each line of the ini file into a readable output string
Dim Kernel As String = ""
'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 As String = ""
Dim Header As String = ""
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 = "&BendLayer"
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
Title = "&SplineTolerance =" & Strings.Left(Title, InStr(Title, " ") - 1)
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")
'I've only seen ini's contain 28100 for linetype and outputs contain 37633, so I've bypassed any testing for different options
Kernel = Kernel & Title & "LineType=37633"
Case Split.Contains("LineWeight")
'Lineweights have the same syntax so I've tagged it onto the converted identifyer
Split = Replace(Split, ";", "")
Kernel = Kernel & Title & Strings.Replace(Split, ".", ",")
Case Split.Contains("Color")
'same as lineweights
Split = Replace(Split, ";", "")
Kernel = Kernel & Title & Strings.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