Hello everyone,
I’m using Rhino 6 at work, and I use a script made by a former colleague to import XCAT phantoms (as Nurbs (.nrb) files) into Rhino. Somehow, the script worked on his workstation, but not on mine, and I can’t see why.
Here is the script :
Sub importPhantomCT
Dim arrPoints, arrCount(1), arrKnots(1), arrDegree(1), arrWeights(1), arrVector
Dim line, srfInfo
Dim iFilesys, iFiletxt
Dim strFilename, strSurface, layerName, material, comp
Dim num_surfs
strFilename = Rhino.OpenFileName("Open...", "NRB Files (*.nrb)|*.nrb||")
If IsNull(strFileName) Then Exit Sub
Rhino.print "Filename = " & strFilename
If Not IsNull(strFilename) Then
Set iFilesys = CreateObject("Scripting.FileSystemObject")
Set iFiletxt = iFilesys.OpenTextFile(strFilename, 1)
num_surfs = 9999
arrDegree(0) = 3
arrDegree(1) = 3
For n = 0 To num_surfs - 1
layerName = iFiletxt.ReadLine 'blank space
layerName = iFiletxt.ReadLine 'title
material = iFiletxt.ReadLine 'material ID
comp = iFiletxt.ReadLine 'material ID
' Rhino.Print "Material = " & CStr(material)
line = iFiletxt.ReadLine
srfInfo = Split(line, " ")
arrCount(0) = CInt(srfInfo(0))
line = iFiletxt.ReadLine
srfInfo = Split(line, " ")
arrCount(1) = CInt(srfInfo(0))
line = iFiletxt.ReadLine
line = iFiletxt.ReadLine 'Ignore 1st zero
arrVector = arrKnots(1)
ReDim arrVector(arrCount(1)+1) 'ignore 1st zero and last 1
For v = 0 To UBound(arrVector)
arrVector(v) = CDbl(iFiletxt.ReadLine)
Next
arrKnots(1) = arrVector
line = iFiletxt.ReadLine 'Ignore last 1
line = iFiletxt.ReadLine
line = iFiletxt.ReadLine 'Ignore 1st zero
arrVector = arrKnots(0)
ReDim arrVector(arrCount(0)+1)
For v = 0 To UBound(arrVector)
arrVector(v) = CDbl(iFiletxt.ReadLine)
Next
arrKnots(0) = arrVector
line = iFiletxt.ReadLine 'Ignore last 1
line = iFiletxt.ReadLine
ReDim arrPoints(arrCount(0)*arrCount(1)-1)
For v = 0 To UBound(arrPoints)
line = iFiletxt.ReadLine
srfInfo = Split(line, " ")
arrVector = arrPoints(v)
ReDim arrVector(2)
arrVector(0) = CDbl(srfInfo(0))
arrVector(1) = CDbl(srfInfo(1))
arrVector(2) = CDbl(srfInfo(2))
' arrVector = Rhino.Str2Pt(line)
arrPoints(v) = arrVector
Next
strSurface = Rhino.AddNurbsSurface(arrCount, arrPoints, arrKnots(0), arrKnots(1), arrDegree)
If Rhino.IsLayer(layerName) Then
Rhino.ObjectLayer strSurface, layerName
Else
Rhino.AddLayer(layerName) '<<<<REMOVED
Rhino.ObjectLayer strSurface, layerName
End If
Rhino.ObjectName strSurface, material & ";" & comp
Next
End If
iFiletxt.Close
End Sub
Rhino.AddStartupScript Rhino.LastLoadedScriptFile
Rhino.AddAlias "importPhantomCT", "_noEcho _-Runscript importPhantomCT"
And the first lines of the .nrb file I try to import :
chest_surface
5
1.0
50 :M
53 :N
U Knot Vector
0.000000
0.000000
0.000000
0.000000
0.020000
0.040000
The thing is, when I launch the script and I select this file, I get nearly immediatly an error message telling me :
Microsoft VBScript Runtime Error
Type Mismatch : 'CDbl'
Line : 43
Car : 4
Code :
This refers to the line " arrVector(v) = CDbl(iFiletxt.ReadLine)", but I can’t see why is there a mismatch.
And obviously, yes, the script worked for this file and many others on my colleague’s workstation (which is unavailable for now on, as my colleague).
Thanks, Vince