Visual Basic (VB) to control/program Rhinoceros V2
Use Rhino3D(V2) as an engine inside of the VB
Problem: How to connect Visual Basic and Rhino so we can use VB forms, ActiveX and other VB flavors.
Here is the basic idea: We'll send the Rhino object from starting/initializing rvb script into VBActiveX and from there we'll control the Rhino from inside of VB. So we'll use the object (Rhinoobject) methods that are available trough the scripting.
Start and select the ActiveX EXE type of project in the VB IDE.
o Create a new class(Rhinoclass.cls) and insert the following code:
Public Sub AXInit(RhinoObject)
Set Rhino = RhinoObject
If IsObject(Rhino) Then
MsgBox ("We don't have an object yet")
o Create new module (Rhinobas.bas) and insert the following code:
Public Rhino As Object
o Create new form (Rhinofrom.frm)
and insert the following code under the buttons i.e.
something like the picture below or anything
Dim cmd As String
cmd = "LINE 0,0 10,10"
Label2.Caption = "Pick a curve"
curve = Rhino.GetObjectId("Pick a curve")
If Rhino.IsCurve(curve) Then
MsgBox "Picked object is a CURVE"
MsgBox "Picked object is NOT a CURVE"
If we want to assign our values to the array inside of VB
we should do it with the following workaround
arrPoint = Rhino.GetPoint("Pick a point")
(without next line AddLine... wont work, Why? it is question of VarArray used in VB and VBArray used trough the scripts)
arrPoint_inf = arrPoint ' << works in Rhino V3 as well or Dim arrPoint(2) As Variant (starting with RhinoV3)
arrPoint_inf(0) = 100
arrPoint_inf(1) = 100
arrPoint_inf(2) = 100
Rhino.AddLine arrPoint, arrPoint_inf
Rhino start up script RhinoVB.rvb
Set RVBobject = CreateObject("Rhinoexe.Rhinoclass")
If IsObject(RVBobject) And IsObject(Rhino) Then 'send Rhinoobject to the VB ActiveX InitClass
RVBobject.AXInit(Rhino) ' object created and exist call class in our executables
Set RVBobject = Nothing
Code to keep our form as a TOP_MOST one
(even if we click in the Rhino window)
All the project files and start up script can be found in here Download VB2Rhino
I've tested the above on the WIN2000 (worked with no problems) & Rhinoceros V2 and it did not work on one of my NT4 boxes??