Detect update scene
-
Hi guys
Is there any way to detect if a scene is being (or has been) updated ? From the documentation, I can see there is no observer method for that. Am I wrong ?
If true, has anyone been able to develop a trick to detect this ? I was thinking about a somehow complicated hack : Storing layer visibility, and compare it with the current visibility when scenes change. But is there an easier way of doing ? -
http://sketchup.com/intl/en/developer/docs/ourdoc/pagesobserver.php#onContentsModified
This spots if any of the pages in the pages-collection have changed, but then you'll need to establish which page [scene] that was ?
You could as you say keep a snapshot collection of pages, each with their layer-sets etc, then compare those against the current collection of pages etc. Now find the changed entries and do whatever it is you are doing [?], then storing the snapshot of the current-collection of pages etc...What is it you seek to achieve ?
-
@tig said:
This spots if any of the pages in the pages-collection have changed
Are you sure ? I tested and it doesn't trigger when a page is updated.
What I'm trying to do is to store layer-groups (from my Layers Panel) state/visibility only when the scene is updated.
I guess I'll just go with that method then. -
The API reads like it's triggered 'when a page changes', but I suspect you are right and it's actually 'when the pages collection change'...
-
@tig said:
The API reads like it's triggered 'when a page changes', but I suspect you are right and it's actually 'when the pages collection change'...
Actually "whenever the pages change", so yeah the pages collection
-
The
Layer
andPage
classes are both a subclass ofEntity
, so you can attach anEntityObserver
subclass to them. Hopefully theonChangeEntity
callback will fire when the user changes a layer visibility state.Also the
Page
class can have it's ownRenderingOptions
hash (separate from the model's hash,) so you can also attach aRenderingOptionsObserver
subclass to individual page's renderingoptions. -
@dan rathbun said:
Also the
Page
class can have it's ownRenderingOptions
hash (separate from the model's hash,) so you can also attach aRenderingOptionsObserver
subclass to individual page's renderingoptions.That's interesting ! Thanks a lot Dan, I'll look into that.
-
@dan rathbun said:
The
Layer
andPage
classes are both a subclass ofEntity
, so you can attach anEntityObserver
subclass to them. Hopefully theonChangeEntity
callback will fire when the user changes a layer visibility state.Confirmed in 2013:
At console:
class EntSpy < Sketchup::EntityObserver; def onChangeEntity(ent); puts "#{ent.inspect} has changed."; end; end
Create a new layer with the Layer Inspector "+" button. It gets name: "Layer1" and is visible by default.
Attach the entity observer:
lay1 = Sketchup.active_model.layers[1] lay1.add_observer(EntSpy.new)
Change "Layer1" visibility by unchecking the box in the Layer Inspector, and the
EntSpy
instance spits out:
%(#000000)["#<Sketchup::Layer:0x536d9a4> has changed."]
It's up to you to figure out how it changed.
-
Oh well, I already use that to track layer's visibility and name changes.
I'm interested in tracking page updates. I guess I'll use exactly the same method -
Hmmm.. I cannot get the EntityObserver to fire when the Page is updated.
-
Hey Jimny be careful with what you are doing as you are conspiring to take out one of the most useful features of your plugin.
The fact is that in your plugin, one of my favorite "features" is that when changing layer visibility, the scene is auto updated. I simply love that!!! The way Sketchup layer manager works is tedious for me as I only use layers for scene management. I suppose there are people that use it in the way you are trying to achieve, but if you could consider my opinion please, please, make that optional.
Thanks and best regards,
JQL
-
@jql said:
make that optional
Ho yeah I will, don't worry
But I myself find usefull that scenes are NOT auto-updated. -
Godspeed then Jiminy!
Best regards,
JQL
-
@jql said:
The fact is that in your plugin, one of my favorite "features" is that when changing layer visibility, the scene is auto updated. I simply love that!!! The way Sketchup layer manager works is tedious for me as I only use layers for scene management. I suppose there are people that use it in the way you are trying to achieve, but if you could consider my opinion please, please, make that optional.
+1
@jiminy-billy-bob said:
But I myself find usefull that scenes are NOT auto-updated.
I would go so far as to request that auto-update be the default
-
@bob james said:
I would go so far as to request that auto-update be the default
No, I think most users expect SU's native functions to behave as usual.
-
@jiminy-billy-bob said:
@bob james said:
I would go so far as to request that auto-update be the default
No, I think most users expect SU's native functions to behave as usual.
I yield to the power
-
@dan rathbun said:
Hmmm.. I cannot get the EntityObserver to fire when the Page is updated.
Me neither... I guess I'll have to check for changes when the active page changes.
-
Actually, that's not even a good solution since users can change layers visibility between the scene update and the active scene change.
Am I stuck ? Hoping that one day Trimble will add this observer method... -
Perhaps if you explain 'in words', what it is you are trying to achieve/trap for then we might better suggest a work-around ??
I understand it your Layer tool 'switches Layers' properties'.
By default it should NOT affect any Scene [Page] layer-settings, unless you have some specific functions in the tool activated by say a button that is clicked by the user: like 'Update Current Scene's Layers' or 'Update All Scenes' Layers' [dangerous!]: then, on running the update function it's easy to get the page [from 'pages.selected_page' or one of the 'pages'], and then reset that page's layers using http://sketchup.com/intl/en/developer/docs/ourdoc/page.php#set_visibility
which allows you to control that page's layers visibility.
You can simply iterate through an array of ON or OFF layers and set them for that page.
page.set_visibility(layer, true)
orpage.set_visibility(layer, false)
Your tool should never reset a page's layers without the user's express knowledge.
If you are changing a layer's property - like 'not displaying on new pages' then the user needs to be aware of the change...
Your dialog needs to get the current layer statuses when it opens.
When a user switches to a scene, then if your dialog is open it needs to get the now current state of the layers; similarly if the user adds a layer or changes a layer-state manually or via another tool ?
BUT if your dialog is set to open as 'modal', then no such changes can be made while the dialog remains open - thus the layer states it gets at startup are always right [unless it's on a MAC which isn't supported anyway!]If this is not helpful then please expand on what it is you are trying to do here ?
-
In my plugin, you can nest layers in groups. By hiding a group, you hide all the nested layers. But, it keeps track of the layer's visibility before they were hidden-by-group. So when you unhide the group, the layers that were previously hidden stay hidden.
(The best way to understand it is to try it yourself )The problem is, when should I store the group's visibility, when I can't know when the scene is updated ?
So yeah, for now I update the scene (only the layers state) every time a layer or group visibility changes. I warn users on the download page, but that's clearly not ideal...
Advertisement