Getting and iterating scene list?
-
Hello,
I do an automated ACAD-import and get some scenes converted from ACAD-views.
Can I get a list with ruby of all existing scenes and iterate through the list
and set each scene activ, zoom to the extents and then update the scene property.When I later click on the scene I get the correct view with all geometry in view.
Regards
Hans-Peter
-
In earlier versions, Scenes where named Pages.
To get list of scenes:
Sketchup.ative_model.pages
Returns aSketchup::Pages
collection object.
https://developers.google.com/sketchup/docs/ourdoc/pagesIterate the collection which return
Sketchup::Page
objects.
https://developers.google.com/sketchup/docs/ourdoc/page -
Hello,
Thanks for the hints.
model = Sketchup.active_model pages = model.pages pages.each {|page| pages.selected_page = page view = model.active_view new_view = view.zoom_extents status = page.update(33) }
Iterating through the pages seems to work.
But they have now all the same view.
How can I get the view of the selected page first and then do the zoom extent on that view?
The page have different viewing angle after import. That should be preserved and only zoomed to extent.
I do not see a page.view or something else.Regards
Hans-Peter
-
When the SketchUp engine does things to the UI on the C++ side, it often returns the Ruby call immediately before things are complete on the C++ side.
In this case, the C++ side is not done animating the camera, when the next Ruby statement executes.
So you can try using
Kernel.sleep
calls to insert pauses. (Adjust till things work right.)require('sketchup.rb') module HPW module SceneUtility @@pages_menu = nil class << self # proxy class def scene_transitions?(model) model.options['PageOptions']['ShowTransition'] end def set_scene_transitions(model,bool=true) bool =( bool ? true ; false ) model.options['PageOptions']['ShowTransition']= bool end def zoom_all_pages_to_extents() model = Sketchup.active_model pages = model.pages trans = scene_transitions?(model) set_scene_transitions(model,false) if trans pages.each {|page| pages.selected_page = page Kernel.sleep(0.5) model.active_view.zoom_extents #status = page.update(33) Sketchup.send_action('pageUpdate;') Kernel.sleep(0.5) } set_scene_transitions(model,trans) end end # proxy class ### RUN ONCE unless file_loaded?(File.basename(__FILE__)) # @@pages_menu = UI.menu('Plugins').add_submenu('Pages') @@pages_menu.add_item('Zoom All Pages To Extents') { zoom_all_pages_to_extents() } file_loaded(File.basename(__FILE__)) # end end # module SceneUtility end # module HPW
If this does not work correctly.. then we'll have to implement a
FrameChangeObserver
. -
Doesn't sleep freeze up SketchUp itself?
-
@thomthom said:
Doesn't sleep freeze up SketchUp itself?
Yes it does.
puts 'foo'; Kernel.sleep(5); puts 'bar';
SketchUp doesn't respond at all until sleep is over. -
@thomthom said:
Doesn't sleep freeze up SketchUp itself?
It should not freeze the C++ side, which should continue animating or zooming the camera. It should only pause the Ruby interpreter.
And I likely showed more time than is needed in at least the first place in the example. The second place is dependent upon how many pages need updating thumbnails, etc.
-
-
@dan rathbun said:
@thomthom said:
@thomthom said:
Doesn't sleep freeze up SketchUp itself?
Yes it does.
puts 'foo'; Kernel.sleep(5); puts 'bar';
SketchUp doesn't respond at all until sleep is over.Apples and Oranges.
puts
is on the ruby side, ... of coursesleep
will pause between the two Ruby statements!I should have been more specific - I cannot interact with SketchUp until sleep is over. The
puts
statements where just visual clues to know when it was over. -
-
It's probably not perfect,.. and I did say this:
@dan rathbun said:
If this does not work correctly.. then we'll have to implement a
FrameChangeObserver
.I'd likely use a
UI.start_timer
block along with aFrameChangeObserver
if the sleep did actually interfer (perhaps SketchUp cannot callViewObserver
orPageObserver
instances during sleep call ??)So.. you could be correct Thomas. This the ol' workaround thingummy again. I wish the API would finish doing certain things, before returning a value from many API method calls (like setting pages, etc.)
-
@thomthom said:
You didn't test it, did you?
Nope.. caught me!
I just whacked it out.
I'll have to drink another cup of coffee, and put in a
FrameChangeObserver
-
Rember, we cannot even use Ruby threads without blocking SketchUp. And wouldnt it be difficult for the Ruby engine to interact with the SketchUp engine and the entities if they ran in a separate thread/process?
-
OK, things seems not so easy.
The scene tab even does first appear after a autosart ruby has run, so no way to access the scenes via shortcut.Other idea: Scenes can store the camera loctation. So can a ruby calculate a new camera location for each scene and write the property.
This would not update the screen or change the visible scene. But next time the scene-change is used it updates to the new location.
And the new camera locations are stored for each scenes in onSave.What Propertys does ZoomExtents set? Is there a equivalent in ruby to calculate the values in the same way?
Regards
Hans-Peter
-
This does what I want:
model = Sketchup.active_model pages = model.pages pages.each {|page| pages.selected_page = page UI.messagebox("Scene; "+page.name) view = model.active_view new_view = view.zoom_extents status = page.update(33) }
But I have to press OK on the messagebox when scene-update has finished.
Edit: Kernel.sleep does not work for that.
-
@hpw said:
Edit:
Kernel.sleep
does not work for that.Yes.. I guess we decided it would not, because the C++ engine cannot call observers, as the scene changes, etc.
Advertisement