Dialog with Webdialog
-
@martinrinehart said:
I have finally got control of communication between Ruby and JavaScript. And I have concluded that, for something small (sending a string from either to the other) this was way too complicated.
Anybody have ideas for making this easier so that those who come after don't have to fight through this stuff?
And an explanation of "skp:get_data@" as an URL would be welcome. An explanation that errs on the side of verbosity would be welcome.
Have a look at this topic and download the plugin. Even if you are not interested in managing scenes (from your book I know you are!) compare the .rb and .js file just to see how easy it is.
@thomthom said:
Yea, I'm not happy about the Ruby/JS link. Converting all data to string and parsing it back into it's correct value... urkh!
If you keep to the key/value concept you can run out arrays from strings that need only be comma delimited:
` list = rubyString.split(",")
for(a=0; a<list.length; a+=2){
if(list[a] == 0){
rn=list[a+1]
sceneReformComponentsArray[rn] = new Array() } //new record
sceneReformComponentsArray[rn][list[a]] = list[a+1] } } //standard`The more you code the keys and values with numbers the smaller your stored string.
@thomthom said:
As you mentioned - with small amount of data it's awkward. With larger amount it's horrible as you'll suffer from the limit you can deal with in an URL (can't remember what this figure is). So larger pieces of data have to be broken into chunks - just to add to the pain.
Just do something like this:
In .html file:
<input id = box type = hidden>
In .js file:
` document.getElementById("box").value = saveR.toString(",")
window.location = "skp:sceneTreeStringSave"`
In .rb file
$dlg.add_action_callback("sceneTreeStringSave") {|d, p| v = d.get_element_value("box") model = Sketchup.active_model create_if_nil = true masterDic = model.attribute_dictionary "master",create_if_nil masterDic[0] = v puts masterDic[0] }
According to Scott:
There doesn't appear to be a limit on the amount of data you can transfer this way with any
of the versions of IE that we test with. (6, 7, andSee also this topic to see how I (and, it seems, RickW) make the interaction between the SU display and web dialog.
Hold tight!
Chris
-
@chrisglasier said:
Even if you are not interested in managing scenes (from your book I know you are!)
Hope you like the book, but you haven't paid for it. Feedback please!
On topic, is it your contention that the existing JS/Ruby communication is as simple as possible? Lots of software is produced with the management directive "We've got to ship something, even if it's ugly." Engineer says (to self) "This is crap but it'll work." and (to boss) "OK, I'll go with what we got."
-
@martinrinehart said:
@chrisglasier said:
Even if you are not interested in managing scenes (from your book I know you are!)
Hope you like the book, but you haven't paid for it. Feedback please!
I understand what you mean but it sounds like I'm a criminal if you don't give the context, viz:
@unknownuser said:
This is commercial, for-profit work. At some point there will be a send-me-money feature added. At this point (mid-summer, 2009) that feature does not exist. The whole price right now is feedback.
The part I might be interested in is not yet started. Are you waiting for SCF to supply enough information, then write it and then charge us. Doesn't sound quite right eh!
As far as I am concerned what exists is good enough to support a business operating system that could be as successful as bar code based operations in supermarkets i.e. we need digital machines more than we need better software.
My regards
Chris
-
@chrisglasier said:
The part I might be interested in is not yet started.
Chris, I tried your plugin. You won't need the Ruby half of the tutorial. You're way past where I'm going.
I'm identifying a small subset of Ruby that is suitable for teaching beginning programmers and then using that language subset to create geometry. For "UI" we'll put pseudo-constants into the beginning of each Ruby and then edit the code:
# stairs.rb RISE = 7 RUN = 9 NSTEPS = 14 ...
Going farther requires Ruby, HTML, CSS and JavaScript - too much for a tutorial on SketchUp modeling.
-
Have you looked at my tutorials on beginning ruby Martin? They are far from perfect, but perhaps might give you some ideas of what you do or do not like about my approach. You know, a starting point to build on, or move away from. Either way, it might be helpful.
They are both located in the sketchucation tutorials section (not the tutorials forum, the actualy tutorials.sketchucation.com place). But I think they are offline currently due to some site remodeling. THey should hopefully be back up shortly.
Chris
-
@chris fullmer said:
Have you looked at my tutorials on beginning ruby Martin?
No, I haven't but I am VERY interested. MartinRinehart at gmail dot com.
-
@martinrinehart said:
Chris, I tried your plugin. You won't need the Ruby half of the tutorial. You're way past where I'm going.
Don't you think as baby-boomers we should offer potential opportunities given our experience, not just regurgitate what already exists?
My regards
Chris
-
@chrisglasier said:
Don't you think as baby-boomers ...
ChrisAs baby boomers? Are you jumping to conclusions?
I'd say more, but I've got to go turn Greetings from Asbury Park over. The A side just finished.
-
@martinrinehart said:
On topic, is it your contention that the existing JS/Ruby communication is as simple as possible? Lots of software is produced with the management directive "We've got to ship something, even if it's ugly." Engineer says (to self) "This is crap but it'll work." and (to boss) "OK, I'll go with what we got."
It's really not too bad. If you give all your form fields an ID, you can reference them in ruby without relying on the info passed in the callback. In fact, there are times I don't pass any data in the callback itself, instead using
dialog.get_element_value("myfield")
to access the information I need. I only pass the info through the callback if the info is limited to one data set, and then only occasionally.
-
@rickw said:
If you give all your form fields an ID, you can reference them in ruby without relying on the info passed in the callback. In fact, there are times I don't pass any data in the callback itself, instead using
dialog.get_element_value("myfield")
to access the information I need. I only pass the info through the callback if the info is limited to one data set, and then only occasionally.
Excellent tip. Thanks.
Advertisement