rvb Import points from text file

points from textfile

After seeing how to export points to excel, now it is turn for us to know how to import back geometry and properties... from any custom file type!

Option Explicit

'Script written by Adolfo Nadal

'Script copyrighted by archi·o·logics www.archiologics.com

'Script version martes, 20 de marzo de 2012 13:21:11

 

Call PointsToRhino()

Sub PointsToRhino()

' Prompt the user for a file to import

Dim strFilter, strFileName

strFilter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*|"

strFileName = Rhino.OpenFileName("Open Point File", strFilter)

If IsNull(strFileName) Then Exit Sub

 

 

' The the file system object

Dim objFSO, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Try opening the text file

On Error Resume Next

Set objFile = objFSO.OpenTextFile(strFileName, 1)

If Err Then

MsgBox Err.Description

Exit Sub

End If

 

Rhino.EnableRedraw False

 

' Read each line from the file

Dim strLine, arrPoint

Do While objFile.AtEndOfStream <> True

strLine = objFile.ReadLine

If Not IsNull(strLine) Then

' Remove any double-quote characters

strLine = Replace(strLine, Chr(34), , 1)

' Convert the string to a 3D point - coordinates must be separated by commas

arrPoint = Rhino.Str2Pt(strLine)

' Add the point to Rhino

If IsArray(arrPoint) Then

' AddPoint will add a point object to Rhino

Rhino.AddPoint arrPoint

End If

End If

Loop

 

Rhino.EnableRedraw True

objFile.Close

Set objFile = Nothing

Set objFSO = Nothing

End Sub

Search Site




archi·o·logics survey

I am interested in: