How to Convert a text file into a matrix

Dear All,

I am fairly new to Rhino Scripts even though I am used to programming. I have been facing something I thought easier to fix.

Basically I have a txt file with only numbers and I would like to extract the numbers I have within this text file and save them into different variables to use later on within the same script.

for example if I open the text file I can see:

1 2 3 4 5 6

I want to read this text file (already done thanks to this forum), and save this into a matrix, let’s say “A”, and use these values by simply calling A(1), A(2) etc.

but apparently there is a problem with the variables. Here is the example of the script:


Dim objFSO, objFile, strFileName, strLine
Const ForReading = 1
strFileName = Rhino.OpenFileName(“Open”, “Text Files (.txt)|.txt||”)
If IsNull(strFileName) Then Exit Sub
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
While Not objFile.AtEndOfStream
strLine = objFile.ReadLine
Rhino.Print strLine
Set objFSO = Nothing

In this way I open the text file and save the information within strLine.

after this I need to do something like:

dim A



and so on with all the elements I have.

but the error I keep getting is:

Type mismatch: ‘A’

Can you please help me on this?

Thank you in advance


If you use Rhino.StrToPtArray

A=Rhino.Str2PtArray("1,2,3 4,5,6 7,8,9")

you will get an nested array of points

((1,2,3), (4,5,6), (7,8,9))


if you use X=A(0) you should get (1,2,3) for X
if you use Y=A(1) you should get (4,5,6) for Y
if you use Z=A(2) you should get (7,8,9) for Z

Is that not what you are seeing?