Option Explicit 'Script written by Ted Ngai Aug 2008 'This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License. 'http://creativecommons.org/licenses/by-sa/3.0/us/ Call ImportEcotectDataFromExcel() Sub ImportEcotectDataFromExcel() ' Declare variables and constants Const xlDown = -4121 Const rhObjectMesh = 32 'Get mesh Dim strObject, arrFaceVertices , arrFace, arrFaceCount, triID strObject = Rhino.GetObject("Select mesh", rhObjectMesh) triID = Rhino.MeshTriangleCount(strObject) If triID > 0 Then Rhino.Print "Cannot process, mesh is triangulated" Exit Sub End If arrFaceVertices = Rhino.MeshFaceVertices(strObject) arrFaceCount = Rhino.MeshFaceCount(strObject) 'Get mesh rows and columns count If IsArray(arrFaceVertices) Then Dim meshRow, meshCol : meshRow = 1 : meshCol = 1 For arrFace = 0 To arrFaceCount-2 meshCol = meshCol + 1 If arrFaceVertices(arrFace+1)(0) - arrFaceVertices(arrFace)(0) > 1 Then meshRow = meshRow + 1 meshCol = 1 End If Next End If meshCol = meshCol+1 meshRow = meshRow+1 Dim sFileName, aPoints() Dim oExcel, oSheet Dim nRow, nRowCount ' Get the name of the file to import sFileName = Rhino.OpenFileName("Select File","Excel Files (*.xls)|*.xls||") If IsNull(sFileName) Then Exit Sub ' Launch Excel and open the specified file Set oExcel = CreateObject("Excel.Application") oExcel.Workbooks.Open(sFileName) ' Get the active worksheet Set oSheet = oExcel.ActiveSheet ' Count the number of rows that need to be processed nRowCount = oSheet.Range("a1", oSheet.Range("a1").End(xlDown)).Rows.Count If (nRowCount = 0 ) Then Rhino.Print "No data range found in file." Exit Sub ElseIf (nRowCount < 2 ) Then Rhino.Print "Not enough points to create curve." Exit Sub End If 'Find min/max values in datas Dim DataList, dataMin, dataMax, DataSort, k ReDim DataList(Rhino.MeshVertexCount(strObject)-1) Set DataSort = CreateObject("System.Collections.ArrayList") k=0 For nRow = 1 To nRowCount Step 2 DataSort.Add oSheet.Cells(nRow, 2).Value DataList(k) = oSheet.Cells(nRow, 2).Value k=k+1 Next DataSort.Sort() DataSort.Reverse() dataMax = DataSort(0) Dim intRed, intGreen, intBlue, arrColors() ReDim arrColors(Rhino.MeshVertexCount(strObject)-1) Dim i, data k=0 For i = 0 To UBound(arrColors) If i > nRowCount/2+meshRow-2 Then arrColors(i) = RGB(0,0,0) ElseIf i Mod meshCol = meshCol-1 Then arrColors(i) = RGB(0,0,0) k=k-1 ElseIf i <= Ubound(dataList) Then data = CInt(DataList(k)) intRed = Abs(Int(data/dataMax*255)) intGreen = Abs(Int(255-(data/dataMax*255))) intBlue = Abs(Int(255-(data/dataMax*255))) arrColors(i)= RGB(intRed,intGreen,intBlue) End If k=k+1 'Rhino.Print "Vex "&i&" is "&arrColors(i) Next Rhino.MeshVertexColors strObject, arrColors ' Close Excel and disassociate object variables oExcel.Quit Set oSheet = Nothing Set oExcel = Nothing End Sub