Forgot password?

Create an account!

Forum

« back

RhinoScript – fso - read 3d points in one line

Messages

Please log in to write a message.

  • 2. Hanno (Dec 27, 2010 13.56):

    Hi,

    reading a complete line is fine. You can then use the Split() function to split the line at tabs like this:

    arrParts = split(yourLine, vbTab)

    This should give you an array of strings that you can convert back to doubles with CDbl()

    Hope that helps!

    Hanno

  • 1. atac (Dec 25, 2010 12.09):

    hello all,

    with the filesystemobject (fs0), I write some 3d point coordinates to a text file.

    Now I want to read these coordinates and store them in one array.

    For example:

    arrPoints (0)
    arrPoints (0)(0) = 2.5525
    arrPoints (0)(1) = 1.2344
    arrPoints (0)(2) = 4.8282

    Is it possible to find the > & vbTab & < to store the next coordinate?

    I took a look at the general description for the filesystemobject (msdn.microsoft.com/en-us/library/d6dw7aeh%28v=vs.85%29.aspx)

    I found a way to read the complete line, but that's not so usefull for my problem.

    Thanks for any help or ideas and have a nice christmas!
    atac


    my test code:

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version Samstag, 25. Dezember 2010 11:02:30

    Dim strfilename,strfiletype

    'strFileType = "SOFiSTiK - Eingaben (*.dat)|*.dat|All Files (*.*)|*.*||"
    strFileType = "TextFile (*.txt)|*.txt|All Files (*.*)|*.*||"

    strFileName = Rhino.SaveFileName("Save TextFile as", strFileType)

    Call writetxtfile()
    rhino.MessageBox("Writing Done")
    Call ReadTxtFile()


    Function WriteTxtFile ()

            Const ForReading = 1, ForWriting = 2
            Dim fso, txt, WriteToFile, i
           
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set txt = fso.CreateTextFile(strfilename, True)
           
            '                         x-coord                       y-coord                         z-coord
            txt.WriteLine("2.5525 " &  vbTab  & "1.2344" &  vbTab  &"4.8282")
            txt.WriteLine("4.1231 " &  vbTab  & "0.2321" &  vbTab  &"2.1002")
            txt.WriteLine("1.2234 " &  vbTab  & "9.1231" &  vbTab  &"8.1282")
            txt.WriteLine("0.1215 " &  vbTab  & "4.2241" &  vbTab  &"2.8211")
            '...
           
            Set txt = fso.OpenTextFile(strfilename, ForReading)
            WriteToFile =   txt.ReadLine
           
    End Function

    Function ReadTxtFile ()

            Const ForReading = 1, ForAppending = 8
            Dim fso, txt, i
            Dim arrResults : ReDim arrResults(0)
            Dim arrPoints                                                                   '
           
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set txt = fso.OpenTextFile(strfilename, ForReading)    
           
            For i = 0 To 3                                                                                                                 
                    arrResults(i) = txt.ReadLine
                    ReDim Preserve arrResults(Ubound(arrResults)+1)
            Next
           
            ReadTxtFile = arrResults
            Rhino.MessageBox(arrResults(1))
           
    End Function

Recommend

Why are these buttons gray?