Detect update scene
-
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...
-
Why do you change a scene's layers automatically?
This is doing something the user's won't anticipate or always want...When the tool opens it 'clones' the current-layers setup - which might be those from a scene-tab OR, if the user has recent manually manipulated the layers and not updated the scene-tab, there could be a mismatch between these two layer-sets... I assume you want to use the 'current-layers' as seen on screen...
I understand that you will want to apply the tool's changes to the current-layers setup 'on screen'... BUT those layers are not necessarily those used by the current Scene tab !
For example, what if I want to manipulate the layers setup and then make a new scene-tab using those - BUT I do NOT want to change the layers setup in the previously current scene-tab, do I ?
So after the user has 'reset the current layers'... can't you just let them 'update' [or create] their scene-tab[s] manually, OR perhaps have a button in your dialog that does 'Apply Changes to Current Scene-tab' ? That way you can use a scene-tab as the source, manipulate the layers on screen, without changing the scene-tab, then either update the scene-tab OR make a new scene-tab using those layers.
Dan's earlier suggestion http://sketchucation.com/forums/viewtopic.php?p=494139#p494139 allows you to spot when a layer's state changes, at that point simply repopulate the dialog with the current layer-settings ? No need to think about pages/scenes...
You will need to attach such an 'entity' observer to all existing layers as the tool is loaded [or a new model is opened etc using an App observer], and also a model.layers_observer to spot when the a new layer is added and then add the 'entity' observer to that too ? This can also spot when current layer changes [which you should not try to switch off]...Your pages observer can spot a page/scene change and repopulate the tool's layers set using the current layers.
This way the pages/page/layers/layer/app observers acting together can always [re]populate your dialog with the current layers setup: the page/scene-tab update should not be automatic - either the user manually updates the scene-tab[s] OR you add a button to do that...
Advertisement