Using Visual Basic 2008 Express dialog form in Ruby.
-
This is an example for using Visual Basic 2008 Express(free version) dialog or form inside Ruby.
Requirment :-- SketchUp ver 7.1
- Visual Basic 2008 Express
The version 27 Oct 09 is Released Version.
You just unzip every file into the Plugins folder, then restart the SketchUp. There is an example inside the zip file.If you want to use this bridges in Ruby, you need OscarVB.rbs and OscarRB.dll which are included inside the zip file, too.
Ruby side:-
Define Sketchup::require 'OscarVB.rbs'And, there are only TWO function in the 'OscarVB.rbs'
-
OscarVB.execute_script(vb_dialog,vb_script,vb_parameter)
vb_dialog -- type string, vb.net form.
vb_script -- type string, vb.net Sub or Function which you defined and want to call.
vb_parameter -- type string, the parameter of the above Sub or Function.
e.g. OscarVB.execute_script("HelloVB.exe","TextBox1_text","Hello! RB!") -
OscarVB.dialog(vb_exe)
vb_exe -- type string, the vb.net form and its' path.
e.g. OscarVB.dialog(File.join(File.dirname(FILE),"HelloVB.exe"))
VB 2008 side:-
Define Dim rb As New OscarRB.Ruby at the top of the code of VB 2008And also, there are only TWO function in the 'OscarRB.dll'(MUST import OscarRB.dll to VB 2008)
-
rb.Open(ByVal vb_dialog As Form)
vb_dialog -- type form, it is the vb.net form.
e.g. rb.Open(Me) 'Put it inside the form load event. -
rb.execute_script(ByVal From_dialog As Form, ByVal To_rbscript As String, Optional ByVal To_rbparameter As String = "")
From_dialog -- type Form, it is the vb.net form.
To_rbscript -- type String, this is the ruby script name which you defined and want to call.
To_rbparameter -- type Optional, String, the parameter of the above def which is ruby script.
e.g. rb.execute_script(Me, "draw_text", TextBox1.Text)[/i]
-
Oscar this is very interesting.
Can you explain what is going behind the scenes in terms of how you are communicating with SU? -
Hai toxicvoxel,
There is a new version which is more stable in the first post.
And don't know you can understand my english's explaination at the above.
Is this "what is going behind the scenes" means how to use it, or others?
Anywhere I do my best! -
Yes, interesting. Does this mean forms can be created using VB express, and used from SketchUp/Ruby?
Is it available across platforms (on a Mac?)
-
Hai Jim,
There is an example inside the zip file.
Yes! The forms is created using VB.Net(free version), and call by SketchUp(MUST be ver 7.1...) ruby.
We can pass the parameter to the form and pass back to SU. It shows in the latest youtube video.
I never try it on Mac, and the dll is build on Windows PC. -
I'm curious?
Does that mean that Grasshopper VB.net code samples can run under Ruby? -
Hi tomot,
May I know that where I can get Grasshopper VB.net code samples, please?
I do try to search in this forum but no result. -
Tomot,
Grasshopper uses the Rhino graphics engine and wouldn't run separately. Unless you wish to execute the grasshopper script, let Rhino do the processing and then return the geometry to Sketchup. - Which would be a little silly as there will be easier ways to achieve it.By the way, calling .NET/COM code from SU Ruby has been available since the first release through ole32.
Talking the other way is a different matter. That is why I have asked for a ruby script to be executable through the Sketchup COM API. Initially HQ agreed it was a good idea but for whatever reason the didn't implement it (since last I checked).
Maybe Oscar will be so kind as to let us know how he achieves the bridge. -
@unknownuser said:
Hi tomot,
May I know that where I can get Grasshopper VB.net code samples, please?
I do try to search in this forum but no result.There are no "Grasshopper VB.net code samples: in this forum, but there are here:
http://en.wiki.mcneel.com/default.aspx/McNeel/GrassHopperGallery.html -
@toxicvoxel said:
Maybe Oscar will be so kind as to let us know how he achieves the bridge.
thanks, I'm also just simply, trying to expand my general understanding
-
This is the example ruby script :
def test input = UI.inputbox ["Ruby says"], ["Hello! VB!"], "Make Friend with VB" OscarVB.dialog(File.join(File.dirname(__FILE__),"HelloVB.exe")) OscarVB.execute_script("HelloVB.exe","Label2_text","Ruby says ; " + input[0]) OscarVB.execute_script("HelloVB.exe","TextBox1_text","Hello! RB!") end
The below is the VB.net script :
Public Class Form1
Dim rb As New OscarRB.RubyI use this two ruby script to call and pass parameter to the below VB.net Sub.
OscarVB.execute_script("HelloVB.exe","Label2_text","Ruby says : " + input[0])
OscarVB.execute_script("HelloVB.exe","TextBox1_text","Hello! RB!")Sub Label2_text(ByVal tx As String) Label2.Text = tx End Sub Sub TextBox1_text(ByVal tx As String) TextBox1.Text = tx End Sub
This is the way we start to connect ruby and vb.net. It is a MUST.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rb.Open(Me) End Sub
Using "End" to Exit the VB.net form.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End End Sub
This is how we execute a ruby script in the VB.net form.
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave rb.execute_script(Me, "draw_text", TextBox1.Text) End Sub
End Class
-
There is a Released Version of OscarVB in the first post.
The two bridges are inside the zip file.
And the free version of VB 2008 Express can be download from the Jim post above.
Thank You! -
This is the youtube link. (I do not know how to get the video inside this forum. ) Thank You
[flash=560,340:2jyf8wrk]http://www.youtube.com/v/hGjFK5o9g-I&hl=en&fs=1&[/flash:2jyf8wrk]
This shows the latest version is more stable.
[flash=560,340:2jyf8wrk]http://www.youtube.com/v/ljVn-F7qxqQ&hl=en&fs=1&[/flash:2jyf8wrk]
-
Hi Oscar,
Could you please just share the source code of your VB.net. It will be useful for me
Thanks in advance !!
-
Who just loads up some guys exes and dlls with no source? Geez, just load up the vb project.
Advertisement