SketchUp can open Web Dialog instance, which is a browser window that is opened within SketchUp.It is possible to make calls from SketchUp to web page or from web page to SketchUp using JavaScript.In these examples Java Script communicates with Ruby. Document files can be stored in the SketchUp plugin folder. They can also be launched via the Ruby console.Data can be shared between Java Script and Ruby. One can utilized Ruby Api.
It provides two mechanisms.
A. One can define a Ruby method that a WebDialog can call.
WebDialog.add_action_callback()
B. One can send data from Ruby to JavaScript.
WebDialog.execute_script()
Creating communication between Ruby on Rails and JavaScript
Creating JavaScript and Ruby communication between Nextselect.rb and Nextselect.html
1. Creating the Web - Dialog instance
my_thi_dialog = UI::WebDialog.new("Multi Actions", false, "Selection Info", 400, 300, 400, 200, true)
2. Creating the communication ( Ruby is expecting a call from JavaScript )
my_thi_dialog.add_action_callback("get_data") do |web_dialog,action_name
( * Java Script from HTML - site )
By Using the skp:callback_method_name method we can invoke the callback method from our web dialog
( Message from Nextselect.html
<script>
function callRuby(actionName) {
query = 'skp:get_data@' + actionName;
window.location.href = query;
} )
Note * Data is sent down to Ruby as a single string. Data is passed via the window.location bar and there is a length limit of 2038 characters.
3. Filepath is the path to the html document
my_thi_dialog.set_file("C:/Program Files/SketchUp/SketchUp 2017/Tools/Nextselect.html")
4. Showing Nextselect.html file
my_thi_dialog.show()