Automating Flat Pattern DXF Export of Parts - almost impossible

Automating Flat Pattern DXF Export of Parts - almost impossible

Anonymous
Not applicable
4,880 Views
9 Replies
Message 1 of 10

Automating Flat Pattern DXF Export of Parts - almost impossible

Anonymous
Not applicable

 

Context:
We are using Inventor Professional 2016.
When a Part file (.ipt) is open you can follow this procedure:

 

1) right click in the Model tree on "Flat Pattern" and select "SaveCopy As ..."
this opens a "Save Copy As" dialog

 

2) here you can select Save as type DXF Files(*.dxf) and click Save
this opens a "Flat Pattern DXF Export Options" dialog

 

3) here you can select various options on three tabs "General",  "Layer" and "Geometry"
You can from this dialog save the selected configuration in an .ini file and reload this at a later time.

 

4) you can also in the "General" tab select to add a "Post Process" DWG/DXF Customize .xml file.

 

5) When you select "OK" a .dxf file is generated according to the selected configuration.


Problem:
We would like to be able to perfom this operation from code (c# Add-in) using the Inventor API.

From various other post we have understood that the DXF translator can't be used for writing out sheet metal flat pattern as DXF.
This is bad new as we hoped to use the configuration .ini file produced by the manual procedure described above.

 

This leaves us to use the DataIO method.

The documentation for this method is very sparse and it uses a format that is totally different from the specification in the configration .ini file.

 

Solution?:

 

We call the DataIO method:

        internal void exportCurrentPartToDxf(Inventor.Document oDoc, string exportPathFileName, string exportCommand)
        {
            if (oDoc is PartDocument)
            {
                PartDocument partDoc = (PartDocument)oDoc;

                if (partDoc.ComponentDefinition is SheetMetalComponentDefinition) {
                    SheetMetalComponentDefinition compDef = partDoc.ComponentDefinition as SheetMetalComponentDefinition;
                    if (useDataIo)
                    {
                        DataIO dataIo = compDef.FlatPattern.DataIO;
                        dataIo.WriteDataToFile(exportCommand, exportPathFileName);
                    }
                }
            }
        }

 


I think we have managed to produce a commandline that matches an inifile from the manual procedure.

 

Inifile:

[FP EXPORT SELECT OPTIONS]
AUTOCAD VERSION=AutoCAD 2004
[FLATPATTERN LAYER OPTIONS]
Tangent Lines=IV_TANGENT:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Bend Lines (Front)=IV_BEND:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Bend Lines (Back)=IV_BEND_DOWN:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Tool Centers (Front)=IV_TOOL_CENTER:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Tool Centers (Back)=IV_TOOL_CENTER_DOWN:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Arc Centers=IV_ARC_CENTERS:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Outer Profile=IV_OUTER_PROFILE:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Inner Profile=IV_INTERIOR_PROFILES:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Feature Profile (Front)=IV_FEATURE_PROFILES:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Feature Profile (Back)=IV_FEATURE_PROFILES_DOWN:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Alternate Rep (Front)=IV_ALTREP_FRONT:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Alternate Rep (Back)=IV_ALTREP_BACK:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Unconsumed Sketches=IV_UNCONSUMED_SKETCHES:Visibility=ON;LinePattern=28100;LineWeight=-1,0000;Color=-255,-255,-255;
Tangent Roll Lines=IV_ROLL_TANGENT:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
Roll Lines=IV_ROLL:Visibility=ON;LinePattern=28100;LineWeight=0,0500;Color=0,0,0;
[FLATPATTERN GEOMETRY OPTIONS]
REBASE GEOMETRY=Yes
GROUP GEOMETRY=Yes
REPLACE SPLINE=Yes
SPLINE SIMPLIFICATION METHOD=Linear
CHORD_TOLERANCE=0,010 mm
TRIM CENTERLINES=Yes

 

 

Commandline (one line)

 

FLAT PATTERN DXF?AcadVersion=2004
&TangentLayer=IV_TANGENT
&TangentLayerLineType=37633
&TangentLayerLineWeight=0,0500
&TangentLayerColor=0;0;0
&BendLayer=IV_BEND
&BendLayerLineType=37633
&BendLayerLineWeight=0,0500
&BendLayerColor=0;0;0
&BendDownLayer=IV_BEND_DOWN
&BendDownLayerLineType=37633
&BendDownLayerLineWeight=0,0500
&BendDownLayerColor=0;0;0
&ToolCenterLayer=IV_TOOL_CENTER
&ToolCenterLayerLineType=37633
&ToolCenterLayerLineWeight=0,0500
&ToolCenterLayerColor=0;0;0
&ToolCenterDownLayer=IV_TOOL_CENTER_DOWN
&ToolCenterDownLayerLineType=37633
&ToolCenterDownLayerLineWeight=0,0500
&ToolCenterDownLayerColor=0;0;0
&ArcCentersLayer=IV_ARC_CENTERS
&ArcCentersLayerLineType=37633
&ArcCentersLayerLineWeight=0,0500
&ArcCentersLayerColor=0;0;0
&OuterProfileLayer=IV_OUTER_PROFILE
&OuterProfileLayerLineType=37633
&OuterProfileLayerLineWeight=0,0500
&OuterProfileLayerColor=0;0;0
&InteriorProfilesLayer=IV_INTERIOR_PROFILES
&InteriorProfilesLayerLineType=37633
&InteriorProfilesLayerLineWeight=0,0500
&InteriorProfilesLayerColor=0;0;0
&FeatureProfilesLayer=IV_FEATURE_PROFILES
&FeatureProfilesLayerLineType=37633
&FeatureProfilesLayerLineWeight=0,0500
&FeatureProfilesLayerColor=0;0;0
&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN
&FeatureProfilesDownLayerLineType=37633
&FeatureProfilesDownLayerLineWeight=0,0500
&FeatureProfilesDownLayerColor=0;0;0
&AltRepFrontLayer=IV_ALTREP_FRONT
&AltRepFrontLayerLineType=37633
&AltRepFrontLayerLineWeight=0,0500
&AltRepFrontLayerColor=0;0;0
&AltRepBackLayer=IV_ALTREP_BACK
&AltRepBackLayerLineType=37633
&AltRepBackLayerLineWeight=0,0500
&AltRepBackLayerColor=0;0;0
&UnconsumedSketchesLayer=IV_UNCONSUMED_SKETCHES
&UnconsumedSketchesLayerLineType=37633
&UnconsumedSketchesLayerLineWeight=-1,0000
&UnconsumedSketchesLayerColor=-255;-255;-255
&TangentRollLinesLayer=IV_ROLL_TANGENT
&TangentRollLinesLayerLineType=37633
&TangentRollLinesLayerLineWeight=0,0500
&TangentRollLinesLayerColor=0;0;0
&RollLinesLayer=IV_ROLL
&RollLinesLayerLineType=37633
&RollLinesLayerLineWeight=0,0500
&RollLinesLayerColor=0;0;0
&RebaseGeometry=True
&MergeProfilesIntoPolyline=True
&SimplifySplines=True
&SplineTolerance=0,010

 

The information form another post "LineType value for Layers in export flat pattern to dxf" was very helpfull.
Using the LinePattern values from the .ini file produced ugly COM exceptions like:
{System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DataIO.WriteDataToFile(String Format, String FileName)

The **LineType parameters values must be taken from the API Enum:

 

LineTypeEnum Enumerator

Name Value Description kChainLineType 37644 Chain line style. kContinuousLineType 37633 Continuous line style. kCustomLineType 37649 Custom line style. kDashDottedLineType 37638 Dash dotted line style. kDashedDoubleDottedLineType 37645 Dashed double dotted line style. kDashedHiddenLineType 37641 Dashed hidden line style. kDashedLineType 37634 Dashed line style. kDashedTripleDottedLineType 37647 Dashed triple dotted line style. kDefaultLineType 37648 default line style. kDottedLineType 37636 Dotted line style. kDoubleDashDoubleDottedLineType 37639 Double dash double dotted line style. kDoubleDashedChainLineType 37637 Double dashed line style. kDoubleDashedDottedLineType 37646 Double dashed dotted line style. kDoubleDashedTripleDottedLineType 37640 Double dash triple dotted line style. kLongDashDottedLineType 37642 Long dash dotted line style. kLongDashedDoubleDottedLineType 37635 Long dashed double dotted line style. kLongDashTripleDottedLineType 37643 Long dash triple dotted line style.

 

Questions:

 

Q1)
Can anybody verify that this is the only way to mimic the manual procedure?

 

Q2)
The "Flat Pattern DXF Export Options" dialog offers a setting called "Trim Centerlines at Contour" - what is the DataIO command param for this?

 

Q3)
Can anyone give us pointers to documentation for the  "Post Process" DWG/DXF Customize .xml file from stetp 4) in the manual process?


Thanks in advance

Lars Lund Hansen

0 Likes
4,881 Views
9 Replies
Replies (9)
Message 2 of 10

adam.nagy
Autodesk Support
Autodesk Support

Hi Lars,

 

1) Yes, that's the only way I'm aware of to do that

2) Brian checked it yesterday for another case and seems like it's not available through the API:
http://forums.autodesk.com/t5/inventor-answer-day/dataio-and-translators/m-p/6009816

3) The documentation for the xml format is in the sample xml file: "C:\Users\Public\Documents\Autodesk\Inventor 2016\Design Data\DWG-DXF\FlatPattern.xml" 

 

Concernig the errors you are running into. Could you provide a minimal, non-confidential sheetmetal part file that could be used to reproduce the issue along with the ini file, etc you are using?  

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 10

TA.Fehr
Advocate
Advocate

I tried using the arguments posted above, and I'm able to create a dxf using the DataIO output command. However, the commands contained display everything in the dxf in the same way as  simply calling 

Dim sOut As String
        sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
        oDataIO.WriteDataToFile(sOut, DXFSource)

I tried renaming the command 

&TangentLayer=IV_TANGENT

To

&TangentLayer=False

 But this only changes the layer name.

 

is there a way to remove specific layers from being output to the dxf file using this method? I opened the xml file but I have no idea how to read it in relation to writing vb.net code.

 

0 Likes
Message 4 of 10

NSBowser
Advocate
Advocate

I've been using the 'iFlatPatternExport' add-in for years to get DXF's of flat patterns. I'm not sure what all functionality you are looking for but it has always handled everything we need to do. You might check it out, before expending too much time trying to reinvent the wheel.

 

http://www.mcadforums.com/forums/viewtopic.php?t=11249

 

Best of Luck,

 


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes
Message 5 of 10

TA.Fehr
Advocate
Advocate

(Edit: Thanks for the reply NSBowser, I'll look into that, but below is the solution that I've made work for my application)

Wouldn't you know, I post a question and find the answer somewhere else.

For those that have the same issue as I do, the way you remove a layer from being exported to the dxf is to add the line "InvisibleLayers =" and include the layer names you want to remove. My example of the sOut string is as follows:

        sOut = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
        "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_Bend_Down;IV_Bend​_Up;IV_ARC_CENTERS"

This will print only the outer and inner profiles and will remove everything else.

This method allows full control over what layers you want shown. To add more customization to the layers exported check out Brian's article here:

 

Message 6 of 10

TA.Fehr
Advocate
Advocate

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

 

 

Message 7 of 10

lmc.engineering
Advocate
Advocate

@TA.Fehr

This is brilliant. Such a useful tool!

Thank you

0 Likes
Message 8 of 10

TA.Fehr
Advocate
Advocate

Glad you found it useful.

I used this as part of a larger project to automate a lot of menial tasks in Inventor.

You can download the setup file here

Feel free to check it out and let me know your thoughts. 

I don't have any tutorials as of yet, but it should be fairly intuitive.

0 Likes
Message 9 of 10

TA.Fehr
Advocate
Advocate

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

 

Message 10 of 10

patrick.kulenkampff
Explorer
Explorer

@TA.Fehr I was looking how to erase a layer and came across with your solution. Thanks for sharing!

0 Likes