Hi Tom, I attach EntitiesObserver, PagesObserver and Pages.add_frame_change_observer on loading extension and then I use AppObserver to attach EntitiesObserver when I open or create a new model.
The initial code on loading my extension is something like this:
@app_Obs = MyExtension::App_Obs.new
@pages_Obs = MyExtension::Pages_Obs.new
@ents_Obs = MyExtension::Ents_Obs.new
@skemaFrameChangeObserverId = Sketchup::Pages.add_frame_change_observer(Frames_Obs.new)
Sketchup.add_observer @app_Obs
Sketchup.active_model.pages.add_observer @pages_Obs
Sketchup.active_model.entities.add_observer @ents_Obs
This is the order I use to add observers.
Later, when you open or create a new model, AppObserver does something like this (only after checking if the observers are not just been added):
if !@observers_just_been_added_for_this_model
Sketchup.active_model.pages.add_observer @pages_Obs
Sketchup.active_model.entities.add_observer @ents_Obs
end
But this second part is not fundamental for my problem that lives when I have only one model opened too.
My problem is about the onActiveSectionPlaneChanged call, this is when I move from a page to another page of the same model. In fact I would aspect that frame and page observers will fire before and onActiveSectionPlaneChanged will fire later. Instead I find that onActiveSectionPlaneChanged fires first of all. Note that onActiveSectionPlaneChanged fires for all sectionPlanes that change (active/unactive) between actual page and the page I’m going to.
Now I made some changes to the deep logic of my extension to bypass this problem at all but I think that, where is possible, Sketchup should fires with this sequence:
When I click on new page or programmatically change Sketchup.active_model.pages.selected_page:
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 0.0%
- ----> Fires onContentsModified in Page Observers
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 1.0%
- ----> Fires onActiveSectionPlaneChanged for the new SectionPlanes status on the destination page compared to the SectionPlanes status on actual page.
Or maybe like this:
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 0.0%
- ----> Fires onContentsModified in Page Observers
- ----> Fires onActiveSectionPlaneChanged for the new SectionPlanes status on the destination page compared to the SectionPlanes status on actual page.
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 1.0%
Now instead the sequence is:
- ----> Fires onActiveSectionPlaneChanged for the new SectionPlanes status on the destination page compared to the SectionPlanes status on actual page.
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 0.0%
- ----> Fires onContentsModified in Page Observers
- ----> Fires frameChange(from_scene, to_scene, percent_done) with percent_done = 1.0%
My opinion is that Frame and Page observers work in an aspected way, onActiveSectionPlaneChanged not.
By the way I understood that the problem is more complex for the “background on the topic of observers in SketchUp” you exposed in your answer.