SketchUcation Premium Membership

 

 

Wish List - WebDialog communication model

Wish List - WebDialog communication model

Postby RichMorin » Fri Jun 01, 2012 5:39 am

Here's another topical breakout from my "SketchUp API Wish List" post:

http://forums.sketchucation.com/viewtopic.php?f=180&t=44949

SketchUp's WebDialogs provide an extremely flexible way to create user interfaces. They can also be used for other purposes (eg, providing access to network services).

However, the way they communicate with plugins is both quirky and peculiar. This forces developers to create workarounds and limits their ability to use familiar design patterns and libraries.

As an example of quirky behavior, execute_script() imposes a fairly small (and undocumented) limit on the size of the executed code string. So, although the call can be used to transfer data (eg, as JSON), any significant amount of data will require multiple calls.

The communication model is also quite peculiar, by current web standards. For example, execute_script(), get_element_value(), and the "location=" hack look nothing like the usual ways of performing communication with a web server.

As a result, common web programming practices (eg, Ajax, REST) are awkward to use. More to the point, many popular JavaScript libraries (eg, Angularjs, Backbone, Knockout) can't be used as-is.

I am not arguing for the removal of the current communication model or anything else that would break existing plugins. However, it should be possible for SketchUp to emulate protocols such as WebSockets and/or XMLHttpRequest.

This would allow literally dozens of JavaScript libraries to be used in WebDialogs. It would also open up possibilities for plugin code that uses common programming idioms (and even code) from Ruby application frameworks such as Rails or Sinatra.
User avatar
RichMorin
 
Posts: 114
Joined: Thu Oct 29, 2009 11:12 pm
Location: San Bruno, CA, USA
Name: Rich Morin
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: interior design
Level of SketchUp: Beginner

Re: Wish List - WebDialog communication model

Postby chrisglasier » Fri Jun 01, 2012 7:35 am

I don't know if something on these lines would be useful for you.

I am using a url inside the webdialog. I do as much as possible in javascript (with ajax and appropriate libraries). At the moment I am working with 2D "components" on html5 canvas (KinectJS library) but I have the beginnings of a sample bridge.rb just to manipulate SU components (using the same data with a few zzzz's added). My main interest is analytical animation both of words and models.
User avatar
chrisglasier
 
Posts: 1014
Joined: Tue Jun 03, 2008 9:11 am
Location: Hong Kong/Zhuhai
Name: Chris Glasier
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: other
Level of SketchUp: Intermediate

Re: Wish List - WebDialog communication model

Postby RichMorin » Fri Jun 01, 2012 8:23 am

chrisglasier wrote:... I do as much as possible in javascript ...


Interesting. My approach (eg, in Igloo Studios' Product Connect suite) has been exactly the reverse: use the thinnest possible layer of JS calls (mostly jQuery) to package up event information and forward it to the plugin code. No doubt, this reflects my preference for coding Ruby...

FWIW, I also did some template-driven JS and HTML generation in the plugin, using ERb, etc. But then, I feel more comfortable with code generation than with hand-editing large amounts of repetitive code.

I'm impressed that you've been able to implement Ajax in the WebDialog environment. However, I suspect that it would have been a lot easier had SketchUp provided emulation of typical web protocols.

Given that most plugin developers are not likely to be JS ninjas, being able to use existing libraries (as-is) still seems like a win...
User avatar
RichMorin
 
Posts: 114
Joined: Thu Oct 29, 2009 11:12 pm
Location: San Bruno, CA, USA
Name: Rich Morin
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: interior design
Level of SketchUp: Beginner

Re: Wish List - WebDialog communication model

Postby thomthom » Fri Jun 01, 2012 9:07 am

I've been building a wrapper that let me create and manipulate many common GUI elements from the Ruby side. Also a better bridge between Ruby and Javascript, where instead of just strings, common object types are transferred. And cleaner ways to call Javascript method, where from Ruby you just use the name of the javascript function and then pass the arguments as you do in Ruby - avoids all the escaping issues etc.

RichMorin wrote:As an example of quirky behavior, execute_script() imposes a fairly small (and undocumented) limit on the size of the executed code string. So, although the call can be used to transfer data (eg, as JSON), any significant amount of data will require multiple calls.

Yes, that is troublesome. And that it's hard to make a GUI that works outside of SketchUp's webdialogs - for testing - as the user agent string only works for the most recent SketchUp version.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Wish List - WebDialog communication model

Postby RichMorin » Fri Jun 01, 2012 2:41 pm

thomthom wrote:... it's hard to make a GUI that works outside of SketchUp's webdialogs - for testing - as the user agent string only works for the most recent SketchUp version.


I hacked up a Browser_Dialog class as a debugging aid:

http://wiki.cfcl.com/bin/view/SketchUp/SketchApps/DF_BD

It mocks up a subset of WebDialog methods and communicates with a browser. Event Machine proxies between temporary files (on the plugin side) and WebSockets (on the browser side). Works amazingly well, all things considered...
User avatar
RichMorin
 
Posts: 114
Joined: Thu Oct 29, 2009 11:12 pm
Location: San Bruno, CA, USA
Name: Rich Morin
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: interior design
Level of SketchUp: Beginner

Re: Wish List - WebDialog communication model

Postby Aerilius » Fri Jun 01, 2012 4:55 pm

Very interesting topic! I agree that communication is not straight-forward (especially when we need to pass a lot of data and let JavaScript call a Ruby method so that Ruby reads a hidden text field in the WebDialog).

A bit unrelated, but I created a small fake program "skp" and registered it in Firefox for the skp: protocol. this way I can debug Javascript and CSS without annoying error messages that Firefox does not know what to do with skp:.
Aerilius
Top SketchUcator
 
Posts: 1111
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: Wish List - WebDialog communication model

Postby chrisglasier » Sat Jun 02, 2012 3:22 am

Here and elsewhere communication models appear to be built on software solutions. A healthier approach is for the communication model to be designed to lead to software solutions. For example webdialogs can be software solutions for viewing communication models assembled by working the Internet as I suggested here and here.

It is worth repeating the quote in that last post:

All of the features of NLS were in support of Engelbart's goal of augmenting collective knowledge work and therefore focused on making the user more powerful, not simply on making the system easier to use.

With this in mind I think it is very wrong to expect those gifted 3d modeling software designers to be responsible for communication modeling beyond the simplest of connections. Those who use Sketchup know what needs to be communicated for whatever they use it for yet there is little support for capturing and modeling their expertise - for example, why has builder Andrew Dwight had to go out on a limb?.
User avatar
chrisglasier
 
Posts: 1014
Joined: Tue Jun 03, 2008 9:11 am
Location: Hong Kong/Zhuhai
Name: Chris Glasier
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: other
Level of SketchUp: Intermediate

Re: Wish List - WebDialog communication model

Postby aadbuild » Tue Jun 05, 2012 7:50 am

thanks Chris, I am not sure if developing custom software is going out on a limb (unless Trimble removes access to the back end of Sketchup). I designed it for me to increase the amount of work that myself and other builders can get done in a day. We are all doing this in one way or another. I hope that the rest of the world will get to reap the benefits of my work in the future. I guess we will find out sooner or later.

My 2 bobs worth is: you can only achieve a certain amount with ruby and using all languages is imperative considering the access we have to Sketchups rear end. :)
Andrew Dwight, NW Sydney Australia
aadbuild.com

Something different done in Sketchup take a look at shipping container transformation. animated in Sketchup

http://www.youtube.com/watch?v=9YxFuJYFgsY
aadbuild
Premium Member
Premium Member
 
Posts: 97
Joined: Sat Jan 05, 2008 9:59 am
Location: Sydney Australia
Name: aadbuild
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Wish List - WebDialog communication model

Postby chrisglasier » Fri Jun 08, 2012 3:49 am

aadbuild wrote:thanks Chris, I am not sure if developing custom software is going out on a limb ...


I don't think there was anything to thank me for, but have a read of this and its related posts. It may be you have put all your eggs in one basket - in which case you are very certainly out on a limb.

Obviously I don't know the detail of your plug in but you mention some interaction with suppliers and so forth. You know most people have JavaScript enabled so if you are relying entirely on Ruby that may go against you. I would really think about minimising Ruby content to the simplest of bridges to Sketchup capturing and manipulating enabling data cross platform.
User avatar
chrisglasier
 
Posts: 1014
Joined: Tue Jun 03, 2008 9:11 am
Location: Hong Kong/Zhuhai
Name: Chris Glasier
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: other
Level of SketchUp: Intermediate

Re: Wish List - WebDialog communication model

Postby Aerilius » Sat Jul 07, 2012 3:08 pm

I'm again struggling with the skp: protocol. It is probably one of the biggest limitations:
  • it supports only ~2083 characters in Internet Explorer
  • it unescapes html named characters (JS sends "& &" and Ruby receives "& &")
    Edit: this is solved by using encodeURIComponent() on the whole string.
  • It eats sometimes backslashes (\ as well as encoded as %5C)
  • If JS sends a single quote (' or %27), Ruby receives nil.
  • On a JavaScript onunload event, we can only send data using this skp method, the more reliable webdialog.get_element_ value("hidden_field") method comes too late when the dialog is already closed.
Last edited by Aerilius on Sun Jul 08, 2012 8:21 am, edited 1 time in total.
Aerilius
Top SketchUcator
 
Posts: 1111
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: Wish List - WebDialog communication model

Postby Dan Rathbun » Sat Jul 07, 2012 4:29 pm

Try building the protocol message as a single-quoted string ??

Also.. the HTMl & codes are not valid in URIs, because & is used mark a field. Special characters should be replaced with %nn hexidecimal codes. ie & is %26
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Wish List - WebDialog communication model

Postby Aerilius » Sat Jul 07, 2012 7:37 pm

Dan Rathbun wrote:Try building the protocol message as a single-quoted string ??

For simple messages yes, but if I can't predict what characters the message contains, I can't simply brute-force replace all double quotes by single quotes.
I ended up writing my own escape function the gets rid of all characters that need escaping (be it for urls or string manipulation). The normal escape function would replace \ by \\ and " by \" which both could later require escaping again (\\\\\\\\\\\\\\\\\\\\\\\\ :) ).
Aerilius
Top SketchUcator
 
Posts: 1111
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: Wish List - WebDialog communication model

Postby Dan Rathbun » Sat Jul 07, 2012 8:04 pm

I have encountered similar "hair-pulling" frustration with the UI.openURL method.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Wish List - WebDialog communication model

Postby Aerilius » Thu Jul 19, 2012 7:15 pm

I've published a code snippet for many of these issues: viewtopic.php?f=180&t=46626
Input appreciated.
Aerilius
Top SketchUcator
 
Posts: 1111
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: Wish List - WebDialog communication model

Postby caseychamberlain » Tue Sep 04, 2012 11:12 pm

RichMorin wrote:As an example of quirky behavior, execute_script() imposes a fairly small (and undocumented) limit on the size of the executed code string. So, although the call can be used to transfer data (eg, as JSON), any significant amount of data will require multiple calls.



What is the limit? I was relying on this to push (sizeable) model data into a silverlight plugin in the WebDialog. I had assumed I needed to chunk, but it would really help to know what that limit is, so I can chunk to that size. :)

Thanks!
caseychamberlain
 
Posts: 1
Joined: Tue Sep 04, 2012 7:38 pm
Name: Casey Chamberlain

Re: Wish List - WebDialog communication model

Postby chrisglasier » Wed Sep 05, 2012 8:52 am

caseychamberlain wrote:
RichMorin wrote:As an example of quirky behavior, execute_script() imposes a fairly small (and undocumented) limit on the size of the executed code string. So, although the call can be used to transfer data (eg, as JSON), any significant amount of data will require multiple calls.



What is the limit? I was relying on this to push (sizeable) model data into a silverlight plugin in the WebDialog. I had assumed I needed to chunk, but it would really help to know what that limit is, so I can chunk to that size. :)

Thanks!


This is the overriding problem:

https://developers.google.com/sketchup/ ... n_callback
User avatar
chrisglasier
 
Posts: 1014
Joined: Tue Jun 03, 2008 9:11 am
Location: Hong Kong/Zhuhai
Name: Chris Glasier
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: other
Level of SketchUp: Intermediate

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Vertex Tools for SketchUp. Take control over each vertex with this vertex editor for SketchUp.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: markhavran and 7 guests