I’m trying to write an Excel VBA script that basically accesses a running Rhino v5 session and pulls in some of the data into a worksheet tab. Unfortunately, I don’t seem to be able to talk to the running session, at least not using the documented steps:
Set Rhino = CreateObject("Rhino5x64.Interface") If (Err.Number <> 0) Then 'MsgBox ("Failed to create Rhino4 object") Set Rhino = CreateObject("Rhino5x64.Application") If (Err.Number <> 0) Then MsgBox "Failed to create Rhino5 object: " & Err.Number Exit Sub End If End If If (Rhino Is Nothing) Then MsgBox ("Failed to get Rhino") End If Do While (nCount < 10) Set RhinoScript = Rhino.GetScriptObject() If Err.Number <> 0 Then Err.Clear Sleep (1000) nCount = nCount + 1 Else Exit Do End If Loop ' Display an error if needed. If (RhinoScript Is Nothing) Then MsgBox ("Failed to get RhinoScript") Else strPath = Chr(34) & Rhino.DocumentPath & Rhino.DocumentName & Chr(34) MsgBox "Current File is: " & strPath Set arrObjects = Rhino.GetObjects(, 0) If IsArray(arrObjects) Then For Each strObject In arrObjects MsgBox "Object identifier: " & strObject Next Else MsgBox "There were no objects" End If End If
The script always kicks back that there’s no file load and has no objects, regardless of what’s loaded into Rhino v5. I’ve tried an alternate method where I try to force Rhino to bring up an open file dialogue box using:
strFile = Rhino.OpenFileName("Open", "Rhino 3D Models (*.3dm)|*.3dm|")
But I’ll get an unsupported method error from Excel. Can anyone explain how to access model data in a Rhino V5 session from within an Excel VBA module?