[How to?] Observer to web dialog A,A&I
-
Just asking seems to push my tiny mind to find the answer ... viz:
Change
@dlg
to$dlg
global variable. Drop the execute_script statement in the observer classdef
. So simple I feel stupid having asked.But I am very pleased to have defined this and hope it will prompt others to use such a device to improve user interaction. Imagine just clicking on a component to display not only its SU attributes but also attributes that may have been gotten via the Internet or directly from local devices. In my view the introduction of observers and web dialogs might just move Sketchup from purely modeling to automated information, phasing out paper style documentation (compare ATMs with cheques or checks).
What do you think?
Chris
-
Some (hopefully) constructive comments:
- The "@" symbol indicates a class instance variable, but you haven't defined a class for your def when you introduce "@def". I'd suggest a new class "ChrisGlasierScenes".
- You add an observer every time "chrisglasierScenes" is run. This will add a lot of overhead. Adding the observer should take place outside any defined methods.
- Globals are generally frowned upon, unless you make sure you have a unique name for them. $dlg is pretty generic, and it's possible someone else could come up with $dlg, and then you (or they) are SOL. That said, after you create the class, you can save an instance of it in a specially-named global variable, like
$chrisglasierScenes = ChrisGlasierScenes.new
You can then access the global when you want the dialog to do something
$chrisglasierScenes.dlg.execute_script(cmd)
Here's a mockup bit of code incorporating my suggestions:
class MySelectionObserver < Sketchup;;SelectionObserver def onSelectionBulkChange(selection) model = Sketchup.active_model selection = model.selection $ChrisGlasierScenes.selected = selection[0].name #includes js array index puts $ChrisGlasierScenes.selected cmd = "sceneSelected('#{selected}');" $ChrisGlasierScenes.dlg.execute_script(cmd) end # def end # class class ChrisGlasierScenes # CREATE A NEW CLASS @@observer_added = false # A CLASS VARIABLE attr_accessor ;dialog, ;selected # PROVIDES ACCESS TO THESE VARIABLES FROM OUTSIDE THE INSTANCE def initialize # THE AUTOMATIC METHOD CALLED WHEN A NEW INSTANCE OF THE CLASS IS CREATED unless @@observer_added # IF THIS IS 'FALSE', THEN YOUR OBSERVER HAS NOT BEEN ADDED YET Sketchup.active_model.selection.add_observer(MySelectionObserver.new) @@observer_added = true # SET TO 'TRUE' SO NO ADDITIONAL OBSERVERS ARE ADDED end @dlg = UI;;WebDialog.new("cgScenes", true, "Scene machine", .... && on and on) end #initialize end #class ChrisGlasierScenes $ChrisGlasiserScenes = $ChrisGlasierScenes || ChrisGlaserScenes.new # SETS THE GLOBAL TO A NEW INSTANCE OF YOUR CLASS, UNLESS IT HAS ALREADY BEEN SET - SAVES OVERHEAD WHEN RELOADING THE .RB FILE
I've used observers combined with dialogs on several of my presentation tools (NightSky was the first ever, then SelectAtStartup, PageUtilities2, SceneExporterPro, CameraControls, and a few others). It's a powerful combination!
-
@rickw said:
Here's a mockup bit of code incorporating my suggestions: ... It's a powerful combination!
I put a link to this topic in a # above the vastly improved code - rather inadequate acknowledgement of your skill and generosity I am afraid.
Many thanks
Chris
-
hi guys sorry to barge in and forgive me if I am off track. I see that you trying to export to web dialog. can I export say out liner, dynamic components ( by layer), groups or scenes? I have been trying for years now to get take offs from sketchup and I am still not there. I can get material quantities and lists to excel from the models. unfortunately they quickly become obsolete when the model is updated. I then have to re export and format the spread sheet to suit my requiremnts. If it where possible to have it update to web continuously I could have my suppliers pricing on the latest take offs when they log in. this would also help with my paperless office attempts
-
I thought I had it all figured out, but obviously I have done something to scupper it.
Here is the top part with my comments marked #CG#:
require 'sketchup.rb' class MySelectionObserver < Sketchup;;SelectionObserver def onSelectionBulkChange(selection) model = Sketchup.active_model selection = model.selection $chrisglasierScenes.selected = selection[0].name #CG# does this need to be global - only used here puts $chrisglasierScenes.selected cmd = "sceneTest('#{selected}');" $chrisglasierScenes.dlg.execute_script(cmd) #CG#don't really understand why this can be attached to a global! end # def end # class class ChrisGlasierScenes # CREATE A NEW CLASS attr_accessor ;dialog, ;selection # PROVIDES ACCESS TO THESE VARIABLES FROM OUTSIDE THE INSTANCE @@observer_added = false # A CLASS VARIABLE def initialize # THE AUTOMATIC METHOD CALLED WHEN A NEW INSTANCE OF THE CLASS IS CREATED unless @@observer_added # IF THIS IS 'FALSE', THEN YOUR OBSERVER HAS NOT BEEN ADDED YET Sketchup.active_model.selection.add_observer(MySelectionObserver.new) @@observer_added = true # SET TO 'TRUE' SO NO ADDITIONAL OBSERVERS ARE ADDED end end #cg# I ended initialize here - is that correct? def ChrisGlasierScenes.cgScenes #CG# I added this - is it correct? Sketchup.send_action "selectSelectionTool;" @dlg = UI;;WebDialog.new("cgScenes02", true, "Scene machine", 300, 205, 0, 0, true) subDir = "chrisGlasierScenes02PC/" fileName = "scene machine.htm" @dlg.set_file File.join(File.dirname(__FILE__), subDir+fileName)
after that there is a bunch of @dlg.add_action_callbacks and then:
@dlg.show() end #cgScenes end #class ChrisGlasierScenes $chrisglasierScenes = $chrisglasierScenes || ChrisGlasierScenes.new # SETS THE GLOBAL TO A NEW INSTANCE OF YOUR CLASS, UNLESS IT HAS ALREADY BEEN SET - SAVES OVERHEAD WHEN RELOADING THE .RB FILE #CG# changed different spellings and capitalisation in mock up if (not file_loaded?("chrisglasierScenes02PC.rb")) UI.menu("Plugins").add_item("cgScenes02" ){ChrisGlasierScenes.cgScenes } end file_loaded("chrisglasierScenes02PC.rb")
If Rick you or anyone else could spot my error(s) I would be most grateful.
Thanks
Chris
-
@aadbuild said:
hi guys sorry to barge in and forgive me if I am off track. I see that you trying to export to web dialog. can I export say out liner, dynamic components ( by layer), groups or scenes? I have been trying for years now to get take offs from sketchup and I am still not there. I can get material quantities and lists to excel from the models. unfortunately they quickly become obsolete when the model is updated. I then have to re export and format the spread sheet to suit my requiremnts. If it where possible to have it update to web continuously I could have my suppliers pricing on the latest take offs when they log in. this would also help with my paperless office attempts
Far from barging in or off track, your participation is appreciated. I think you are one of few seriously pursuing the paperless office. This pursuit is made harder because office software is all about documents - digital equivalent of paperwork. We don't offer an ATM a cheque (check) because it needs a human being to interpret it; instead we use a digitised card. So if we want to automate we need to make digitised objects (they can be virtual). The working environment becomes object not document oriented.
This topic is part of that, making the Sketchup display into a digital machine. When you select entities immediately you receive information about them in the webdialog. And of course there can be various integral devices that deal with tasks like the requests for quotations you mention.
So I think it is wrong to think of this as exporting data. This is more an operating system, a mix of structured information and coding, that can be plugged into applications like Sketchup to set or get data, directly, from the app's display or via the web. Instead of using Excel and email you simply make your selections and click submit (like an SCF post) to make your quotation requests.
So far the first small step after introducing the concept of namesets was the cgScenes 1.04 plugin. This reduces the necessity of opening and closing layer, outliner, style and scene windows and view menu when managing scenes. No big deal but it does substitute some human effort with automation - it has moving parts; it is a machine.
The next step which I am struggling to complete (see previous post) is to expand the machine so that you can identify and navigate all parts of projects. It provides new indexes to run above layers, groups and outliner. These are nested so that you can move through various levels from the project to individual component or scene. There are six indexes: assembly (like a room), batch (like sanitaryware), concept (like fire precautions), dimension, label and scene.
Scenes can be categorised by purpose such as presentation, setting out, layout, schedule, inventory, detail and trade. Dimensions and label selections use the SU layer system but assembly, batch and concept turn components on and off by level heading and/or individually. (All respective layers are turned on.) One big advantage is that components don't get stuck in one layer or group, so, for example, a tiled floor can appear in an assembly (room), batch (floor finishes) or concept (hygiene).
So the best I can offer to relieve your take off (bill of material) problems and bolster your paperless office aspirations, is that I will do my best to get the new version out, and then we can discuss what devices are needed to operate your house building business.
My regards
Chris
-
@chrisglasier said:
I thought I had it all figured out, but obviously I have done something to scupper it.
Here is the top part with my comments marked #CG#:
require 'sketchup.rb' > > class MySelectionObserver < Sketchup;;SelectionObserver > def onSelectionBulkChange(selection) > model = Sketchup.active_model > selection = model.selection > $chrisglasierScenes.selected = selection[0].name #CG# does this need to be global - only used here #RW# Yes, it references $chrisglasierScenes, which is set in your next code block - it is used to create a single instance of your class. > puts $chrisglasierScenes.selected > cmd = "sceneTest('#{selected}');" > $chrisglasierScenes.dlg.execute_script(cmd) #CG#don't really understand why this can be attached to a global! #RW# the global references an instance of your class. Conceptually, it's really no different than "model = Sketchup.active_model". Perhaps the confusing part is that the global is defined near the end of the code, but referenced earlier in code blocks. It has to be set at the end; otherwise, it will return an error because the class it wants to be an instance of is not yet undefined. > end # def > end # class > > > class ChrisGlasierScenes # CREATE A NEW CLASS > > attr_accessor ;dialog, ;selection # PROVIDES ACCESS TO THESE VARIABLES FROM OUTSIDE THE INSTANCE > @@observer_added = false # A CLASS VARIABLE > > def initialize # THE AUTOMATIC METHOD CALLED WHEN A NEW INSTANCE OF THE CLASS IS CREATED > @model = Sketchup.active_model > unless @@observer_added # IF THIS IS 'FALSE', THEN YOUR OBSERVER HAS NOT BEEN ADDED YET > Sketchup.active_model.selection.add_observer(MySelectionObserver.new) > @@observer_added = true # SET TO 'TRUE' SO NO ADDITIONAL OBSERVERS ARE ADDED > end > end #cg# I ended initialize here - is that correct? #RW# yes > > ###def ChrisGlasierScenes.cgScenes #CG# I added this - is it correct? #RW# it depends. If you want to call the method without an instance, yes. Since $chrisglasierScenes is created as an instance, it is not necessary - you can use "def cgScenes" > > def cgScenes > Sketchup.send_action "selectSelectionTool;" > @dlg = UI;;WebDialog.new("cgScenes02", true, "Scene machine", 300, 205, 0, 0, true) > subDir = "chrisGlasierScenes02PC/" > fileName = "scene machine.htm" > @dlg.set_file File.join(File.dirname(__FILE__), subDir+fileName) >
after that there is a bunch of @dlg.add_action_callbacks and then:
> > @dlg.show() > end #cgScenes > end #class ChrisGlasierScenes > > $chrisglasierScenes = $chrisglasierScenes || ChrisGlasierScenes.new # SETS THE GLOBAL TO A NEW INSTANCE OF YOUR CLASS, UNLESS IT HAS ALREADY BEEN SET - SAVES OVERHEAD WHEN RELOADING THE .RB FILE > #CG# changed different spellings and capitalisation in mock up > > unless file_loaded?("chrisglasierScenes02PC.rb") > file_loaded("chrisglasierScenes02PC.rb") > ($submenu) ? (submenu = $submenu) ; (submenu = UI.menu("Plugins")) > submenu.add_item("cgScenes02" ){ $chrisglasierScenes.cgScenes } > end #RW# edited to be compatible with Organizer ;) and to not repeat the "file_loaded" call when reloading. >
If Rick you or anyone else could spot my error(s) I would be most grateful.
Thanks
Chris
Here you go, with added comments tagged with #RW#.
-
@rickw said:
Here you go, with added comments tagged with #RW#.
Sorry Rick but I get this with a new component in a newly opened file:
and nothing here:
with the same model in which $dlg works:
I tried changing this:
attr_accessor :dialog, :selection
toattr_accessor :dialog, :selected
- no effect.Thanks for all your comments, very useful for a reluctant coder like me! I am more familiar with JavaScript so I struggle quite a bit with Ruby. If you can spot the problem(s) please let me know. I can send the files but it seems presumptuous to do so here.
Thanks again
Chris
edit 1600hrs : also get nothing after I save the cylinder model
-
Thanks for your PM Rick.
-
@aadbuild said:
I may be able to help you a little with identifying components and materials I have several rubies that do this. Tf rubies does a great job of exporting timber and grouping it. We are also working on a ruby that searches sketchup for materials and then gives square meters by material and also lineal metrs by component. great fo a comprehensive break down.
That would be good; could you email me with them? Also would you be prepared to let me have one of your models? One part of cgScenes 2 analyses what already exists in a model and reforms it to start off the six indexes I describe above.
@unknownuser said:
We need to bring on the paperless office as quick possible
I agree; that's why I am so interested in developing alternatives in webdialogs.
Thanks
Chris
-
[
Advertisement