Last active
April 8, 2016 06:34
-
-
Save theTonyHo/0d2496e5b7733e4604e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Experiment communication with Rhinoceros 3D application. | |
' This is useful for interopability from Excel and/or other windows programs using VBA/VBscript. | |
' Author: Tony Ho | |
' Date: 08/04/2016 | |
' References: http://v5.rhino3d.com/forum/topics/rhino-automation-through-com | |
Option Explicit | |
Public rhApp As Object | |
Public rhSO As Object | |
Function GetRhinoInstance(Optional show As Boolean, Optional focus As Boolean) As Object | |
'Get AutoCAD App | |
On Error Resume Next | |
Set rhApp = Nothing | |
Set rhApp = CreateObject("Rhino5x64.Interface") | |
If Err Then | |
'Launch if not open | |
Debug.Print "Launching Rhinoceros Application" | |
Set rhApp = CreateObject("Rhino5x64.Application") | |
End If | |
Err.Clear | |
If show Then rhApp.Visible = True | |
If focus Then rhApp.BringToTop | |
Set GetRhinoInstance = rhApp | |
End Function | |
Sub Test() | |
GetRhinoInstance (False) | |
Set rhSO = rhApp.GetScriptObject | |
rhSO.Command ("SentFromExcel") | |
End Sub | |
Sub TestAddPoint() | |
Dim rhApp | |
Set rhApp = GetRhinoInstance(True) | |
Dim rhSO As Object | |
Set rhSO = rhApp.GetScriptObject | |
Dim aPt(2) As Variant | |
aPt(0) = 20.5 | |
aPt(1) = 60.5 | |
aPt(2) = 20.5 | |
rhSO.AddPoint (aPt) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment