Forgot password?

Create an account!

Forum

« back

RhinoScript – How to read a point text file into Rhino

Messages

Please log in to write a message.

  • 3. Ning (Jun 08, 2010 18.27):

    Johannes,

    Thank you so much. CDbl does sort my problem out.

    Best Wishes

    Ning

  • 2. Johannes (Jun 08, 2010 18.01):

    Hi,

    just use the Cdbl() function to convert the text string into a double instead of Rhino.Str2Pt().

    Option Explicit

    Call Main()
    Sub Main()
            Dim file_path
            file_path = Rhino.OpenFileName("Open", "Text Files (*.txt)|*.txt|All Files|*.*")
            If (IsNull(file_path)) Then Exit Sub
           
            Dim contents
            Dim arrPoint(2)
            contents = Rhino.ReadtextFile(file_path, True, True)

            Dim i

            For i = 0 To UBound(contents)
                    Dim fragments
                    fragments = Split(contents(i), ";")
           
                    arrPoint(0) = CDbl(fragments(0))
                    arrPoint(1) = CDbl(fragments(1))
                    arrPoint(2) = CDbl(fragments(2))
                   
                    Call Rhino.Print(Rhino.Pt2Str(arrPoint))
                    Call Rhino.addPoint(arrPoint)
                   
            Next
    End Sub

    Johannes

  • 1. Ning (Jun 08, 2010 17.36):

    Hi,

    I have a simple but really serious problem in the code below. I am struggling to use the code to import a point text file into Rhino. Unfortunately the code does not work due to the error "Type dismatch in parameter, float required".

    First, let me show me the format of my point text file, which has 15000 line and each line has three cocordinate values

    503.256789971;-261.378431993;0.0
    517.926788564; -261.372005769; 0.0
    526.8115; -249.255109375; 0.0
    522.81146875; -249.256859375; 0.0
    522.8099375; -245.718453125; 0.0
    526.81075; -247.626703125; 0.0

    Secondly, let me show you the coed below

    Option Explicit

    Call Main()
    Sub Main()
            Dim file_path
            file_path = Rhino.OpenFileName("Open", "Text Files (*.txt)|*.txt|All Files|*.*")
            If (IsNull(file_path)) Then Exit Sub
           
            Dim contents
            Dim arrPoint(2)
            contents = Rhino.ReadtextFile(file_path, True, True)

            Dim i

            For i = 0 To UBound(contents)
                    Dim fragments
                    fragments = Split(contents(i), ";")
           
                    arrPoint(0) = Rhino.Str2Pt (fragments(0))
                    arrPoint(1) = Rhino.Str2Pt (fragments(1))
                    arrPoint(2) = Rhino.Str2Pt (fragments(2))
                   
                    Call Rhino.Print(Rhino.Pt2Str(arrPoint))
                    Call Rhino.addPoint(arrPoint)
                   
            Next
    End Sub

    The code looks simple. I had spent more than 3 hours on it and still cannot fix it. Could you please take a look at it and help me out? Thank you so much.

    Best Wishes

    Ning

Recommend

Why are these buttons gray?