the mothed is “def update_multiple(x)” in “class Html_Update < Sketchup::SelectionObserver”.
this method is binding to a HtmlDialog in “add_action_callback”.
when i callback from HtmlDialog, i get a “Error: #<NoMethodError: undefined method `update_multiple’ for Zhouxi::Indexz::Html_Update:Class>”
The UI::HtmlDialog#add_action_callback’s block itself creates the callback method defined in the UI::HtmlDialog dialog instance, not in another class. (Ie, the block defines a singleton method upon the particular dialog object instance.)
But you can always have the action callback’s block then call another object’s method if you wish.
(1) Ruby uses 2 space indentation. This helps also minimize horizontal scrolling in forum snippets.
(2) All API observer classes are abstract.
This means that you gain nothing by subclassing them as they have no superclass functionality to pass down to subclasses.
All observer attach methods do no class checking at all. This means that any kind of object can be an observer, of any kind, at all times. Ie, hybrid observer objects.
So basically your use of the Html_Update as a class is not correct. You only create a class if your code will be making many instances of such class.
You don’t need a class here. Just use an extension submodule (ie, IndexZ) and extend it with itself …
module Zhouxi
module IndexZ
extend self
Now you methods can be called without the self. qulaification.
(3) For HTML, …
<meta> tags need to be within the <head> element.
Your HTML should always begin with a <!DOCTYPE html> tag. (ie, the 1st line before <html>.)
(4) Your add_action_callback must be called before you create the dialog with #show.
AND … if the user closes the dialog, and then your code opens it again (say, with a toolbar button) then you must reattach the action callback proc. (Closing a UI::HtmlDialog instance window breaks the link to the callback procs.)
(5)Outdenting SUCKS. Please don’t do this. Outdenting breaks the editor’s indent guidelines.
(6) Avoid the use of @@ class variable references unless you really understand how to use them.
In your case, you should really only be using @ instance variables of the extension module’s instance. (Meaning, a module is an instance of class Module. So it can have it’s own instance variables.)
Learn how to build hashes of Ruby object data, then create a JSON string of this hash.
Then pass the JSON string to the HTML using #execute_script.
i did some tests today, and have some results, pls tell me if i am wrong. @DanRathbun
1. i think subclassing do gain something.
for example,i can add some new method and variables to the class without worrying conflicts.
2. add_action_callback seems cant call any method outside, but variables.
so in my case,i defined a new subclass (IndexzHtml) of UI::HtmlDialog,added all the methods in it.