Ok. I believe I may have figured out how to reference my file. I did
it via a string component and and right clicking and "Set String" and
placing the file name including path. Assuming that is how you do that
now I have to figure out how to write something that will parse the
values using something like a Tokenizer...Though I can roughly
understand rhinoscript I can't really write it and I don't know how to
translate it to VB.net. I am wondering if anyone has anything that
does the following, but written in VB.net
Option Explicit
Call gImport()
Sub gImport()
' Prompt the user for a file to import
Dim strFilter, strFileName, agents()
strFilter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*||"
strFileName = Rhino.OpenFileName("Open Point File", strFilter)
If IsNull(strFileName) Then Exit Sub
Dim arrNames(4), strName
arrNames(0) = "points"
arrNames(1) = "pointsData"
arrNames(2) = "lines"
arrNames(3) = "splines"
arrNames(4) = "vectors"
strName = Rhino.GetString("import what sort of custom file format", ,
arrNames)
' 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 and pass to the appropriate build
function
Dim strLine, arrPoint, counter, fileType
counter = 0
Do While objFile.AtEndOfStream <> True
strLine = objFile.ReadLine
If Not IsNull(strLine) Then
' Remove any double-quote characters
strLine = Replace(strLine, Chr(34), "", 1)
Select Case strName
Case "pointsData"
obj = buildPointsData(strLine) 'adds
points with object data
Case "lines"
obj = buildLines(strLine) 'adds lines
Case "splines"
obj = buildSplines(strLine) 'adds line
Case "vectors"
obj = buildVectors(strLine) 'adds lines
Case Else
obj = buildPoints(strLine) 'adds points
End Select
' add to an array
ReDim Preserve agents(counter - 1)
agents(counter - 1) = obj
End If
counter = counter + 1
Loop
Rhino.EnableRedraw True
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Function buildPoints(strLine)
Dim arrPoint, pt, i, arrTokens
' convert the first string to a 3D point
arrPoint = Rhino.Str2Pt(strLine)
' Add the point to Rhino
If IsArray(arrPoint) Then
pt = Rhino.AddPoint(arrPoint)
End If
buildPoints = pt
End Function
Function buildPointsData(strLine)
Dim arrPoint, pt, i, arrTokens
arrTokens = Rhino.Strtok(strLine)
' convert the first string to a 3D point
arrPoint = Rhino.Str2Pt(arrTokens(0))
' Add the point to Rhino
If IsArray(arrPoint) Then
pt = Rhino.AddPoint(arrPoint)
' add object data to point
For i = 1 To UBound(arrTokens)
Rhino.SetObjectData pt, "agentAttribute", arrTokens(i*2
- 1),
arrTokens(i*2)
Next
End If
buildPointsData = pt
End Function
Function buildLines(strLine)
Dim arrPoint1, arrPoint2, line, arrTokens
arrTokens = Rhino.Strtok(strLine)
' convert the first string to a 3D point
arrPoint1 = Rhino.Str2Pt(arrTokens(0))
arrPoint2 = Rhino.Str2Pt(arrTokens(1))
' Add a line to Rhino
line = Rhino.AddLine(arrPoint1, arrPoint2)
buildLines = line
End Function
Function buildSplines(strLine)
Dim arrPoint1, arrPoint2, line, arrTokens, arrPoints(), i
arrTokens = Rhino.Strtok(strLine)
' loop to convert to points
For i = 0 To UBound(arrTokens)
ReDim Preserve arrPoints(i)
arrPoints(i) = Rhino.Str2Pt(arrTokens(i))
Next
' Add a spline to Rhino
line = Rhino.AddCurve(arrPoints)
buildSplines = line
End Function
Function buildVectors(strLine)
Dim arrPoint1, arrPoint2, line, arrTokens
arrTokens = Rhino.Strtok(strLine)
' convert the first string to a 3D point
arrPoint1 = Rhino.Str2Pt(arrTokens(0))
arrPoint2 = Rhino.Str2Pt(arrTokens(1))
' Add the leader to Rhino
line = Rhino.AddLeader(Array(arrPoint1, arrPoint2))
buildVectors = line
End Function