úterý 19. července 2016

editace textu dxf pro vb.net

Můj pokus ve vb.netu   o konzolovou aplikaci která pomocí argumentů zpracovává  dxf soubory
stručně: 
nejde řádek polyline 
pokud na 9 řádku od polyline je hodnota " 40" tan na další řádku zapíše "0"
pokud na 11 řádku od polyline je hodnota " 41" tan na další řádku zapíše "0"

celé to slouží k tomu aby z PDMS lezly polyline s tloušťkou nastavenou na 0, kvůli správnému CTB tisku v autocadu. 

kód: 


Imports System.IO

Module Module1
    'Sub Main(ByVal args() As String)
    Sub Main()
        Dim argus As String() = Environment.GetCommandLineArgs()
        If argus.Length = 1 Then
            Console.WriteLine("Help -this app read dxf file and search value 0.100000E-01 and replacet to 0 ")
            Console.WriteLine("sytax: zerothic.exe c:\file.dxf")
            Console.WriteLine("output is same filename with !-prefix")
            Exit Sub
        End If
        Dim ZdrFile As String = argus(1)
        If Not Path.GetExtension(ZdrFile) = ".dxf" Then
            Console.WriteLine("Error - File must be dxf type")
            Exit Sub
        End If

        If Not My.Computer.FileSystem.FileExists(ZdrFile) Then
            Console.WriteLine("Error - File doesnt' exist")
            Exit Sub
        Else
        End If
        Dim f As Integer = FreeFile()
        Dim TextLine As String = ""
        Dim CilFile As String
        CilFile = Path.GetDirectoryName(ZdrFile) & "\!" & Path.GetFileName(ZdrFile)

        Dim objReader As New System.IO.StreamReader(ZdrFile)
        Dim objWriter As New System.IO.StreamWriter(CilFile)
        Dim CisloRadek As Integer = 1
        Dim polyradek As Integer
        Dim zpracuj As Boolean = False

        Do While objReader.Peek() <> -1
            TextLine = TextLine & objReader.ReadLine()

            If zpracuj = True Then
                objWriter.Write("0" & vbNewLine)
                zpracuj = False
            Else
                If TextLine = "POLYLINE" Then
                    polyradek = CisloRadek
                End If

                If ((CisloRadek = polyradek + 7) And (TextLine = " 40")) Or ((CisloRadek = polyradek + 9) And (TextLine = " 41")) Then
                    zpracuj = True


                End If

                objWriter.Write(TextLine & vbNewLine)
                TextLine = ""

            End If
            CisloRadek = CisloRadek + 1
            TextLine = ""
        Loop
        objWriter.Close()

    End Sub
End Module