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 Dim arrCenters arrCenters = Rhino.MeshFaceCenters(strObject) Dim sFileName, aPoints(), meshFaceID, nMag Dim oExcel, oSheet, 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 ' Re-dimension the resulting array of points accordingly ReDim meshFaceID((nRowCount-1)/2+1) ReDim nMag((nRowCount-1)/2+1) ' Process all rows Rhino.Print "Importing data..." arrFace = 0 For nRow = 1 To nRowCount Step 2 ' Read the values from columns A, B, and C meshFaceID(arrFace) = oSheet.Cells(nRow, 1).Value nMag(arrFace) = oSheet.Cells(nRow, 2).Value Rhino.Print meshFaceID(arrFace) Rhino.AddTextDot nMag(arrFace), arrCenters(arrFace) ' values and add it to the array of points If meshFaceID(arrFace) = (meshCol*((arrFace+1)*2))-1 Then nRow = nRow + 1 End If arrFace = arrFace +1 Next ' Close Excel and disassociate object variables oExcel.Quit Set oSheet = Nothing Set oExcel = Nothing End Sub