Excel Import to Rhinoscript

Example Rhinoscript to import excel files into variables.


Option Explicit
'excel import to rhinoscript , che-wei wang 4.8.2008		
'excel cell numbers begin with 1,1 (not 0,0)

Call Main()
Sub Main()
	Dim FileName, file, excel
	FileName = Rhino.OpenFileName("Select Excel File","Excel Files (*.xls)|*.xls||")
	If isNull(FileName) Then Exit Sub
		
	Set excel = CreateObject("Excel.Application")
	excel.Visible = True
	
	excel.Workbooks.Open(FileName)
	Set file = excel.ActiveSheet

	Dim x:x= file.Cells(1,2).Value
	
	Call Rhino.Print(x)

	
	excel.UserControl = True
End Sub

3 comments

  1. Hey your scipt is great but i have a problem running it.
    I added it as a function and it runs great but it opens a new excel instance anytime I run it. have any ideas how to fix this?
    thanks.
    Option Explicit
    ‘Script written by
    ‘Script copyrighted by
    ‘Script version Wednesday, April 07, 2010 8:22:36 PM

    Call Main()
    Sub Main()
    Rhino.EnableRedraw False
    Rhino.Print “script started”
    Dim arrCurves : arrCurves = Rhino.objectsbylayer(“default”)
    ‘ReDim arrObjs(arrCurves)
    ‘Dim Counta : Counta = 2
    Dim a
    For a = 0 To ubound (arrCurves)
    Dim strCent : strCent = Rhino.CurveAreaCentroid(arrCurves(a))
    Dim dist : dist = exceldata ((a)+2,(4))
    ‘Rhino.Print dist
    Dim newpt : newpt = Array(strCent(0)(0)+(2),strCent(0)(1),strCent(0)(2))
    ‘Rhino.Print newpt
    Dim strpath : strpath = Rhino.addline(strcent(0),newpt)
    Dim strNewObj : strNewObj = Rhino.extrudecurve(arrCurves(a),strpath)
    ‘arrObjs(a) = strNewObj
    Rhino.DeleteObject strpath
    ‘Counta = Counta+1

    Next
    Rhino.Print “script completed”
    Rhino.EnableRedraw True
    Rhino.Redraw

    End Sub
    Function exceldata (a,b)
    Dim FileName, file, excel
    FileName = “C:\Users\johncameronpalm\Desktop\master\centercitymaster1”
    ‘If isNull(FileName) Then Exit Function

    Set excel = CreateObject(“Excel.Application”)
    excel.Visible = False

    excel.Workbooks.Open(FileName)
    Set file = excel.ActiveSheet

    Dim x:x= file.Cells(a,b).Value

    Call Rhino.Print(x)

    excel.UserControl = True
    End Function

Comments are closed.