sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Detect update scene

    Scheduled Pinned Locked Moved Developers' Forum
    34 Posts 5 Posters 4.2k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jiminy-billy-bobJ Offline
      jiminy-billy-bob
      last edited by

      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 ?

      25% off Skatter for SketchUcation Premium Members

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • jiminy-billy-bobJ Offline
          jiminy-billy-bob
          last edited by

          @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.

          25% off Skatter for SketchUcation Premium Members

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • jiminy-billy-bobJ Offline
              jiminy-billy-bob
              last edited by

              @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 πŸ˜„

              25% off Skatter for SketchUcation Premium Members

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                The Layer and Page classes are both a subclass of Entity, so you can attach an EntityObserver subclass to them. Hopefully the onChangeEntity callback will fire when the user changes a layer visibility state.

                Also the Page class can have it's own RenderingOptions hash (separate from the model's hash,) so you can also attach a RenderingOptionsObserver subclass to individual page's renderingoptions.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • jiminy-billy-bobJ Offline
                  jiminy-billy-bob
                  last edited by

                  @dan rathbun said:

                  Also the Page class can have it's own RenderingOptions hash (separate from the model's hash,) so you can also attach a RenderingOptionsObserver subclass to individual page's renderingoptions.

                  That's interesting ! πŸ˜„ Thanks a lot Dan, I'll look into that.

                  25% off Skatter for SketchUcation Premium Members

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @dan rathbun said:

                    The Layer and Page classes are both a subclass of Entity, so you can attach an EntityObserver subclass to them. Hopefully the onChangeEntity 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.

                    😎

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • jiminy-billy-bobJ Offline
                      jiminy-billy-bob
                      last edited by

                      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 πŸ˜„

                      25% off Skatter for SketchUcation Premium Members

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        Hmmm.. I cannot get the EntityObserver to fire when the Page is updated.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • JQLJ Offline
                          JQL
                          last edited by

                          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

                          www.casca.pt
                          Visit us on facebook!

                          1 Reply Last reply Reply Quote 0
                          • jiminy-billy-bobJ Offline
                            jiminy-billy-bob
                            last edited by

                            @jql said:

                            make that optional

                            Ho yeah I will, don't worry πŸ˜‰
                            But I myself find usefull that scenes are NOT auto-updated.

                            25% off Skatter for SketchUcation Premium Members

                            1 Reply Last reply Reply Quote 0
                            • JQLJ Offline
                              JQL
                              last edited by

                              Godspeed then Jiminy!

                              Best regards,

                              JQL

                              www.casca.pt
                              Visit us on facebook!

                              1 Reply Last reply Reply Quote 0
                              • Bob JamesB Offline
                                Bob James
                                last edited by

                                @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

                                i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

                                1 Reply Last reply Reply Quote 0
                                • jiminy-billy-bobJ Offline
                                  jiminy-billy-bob
                                  last edited by

                                  @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.

                                  25% off Skatter for SketchUcation Premium Members

                                  1 Reply Last reply Reply Quote 0
                                  • Bob JamesB Offline
                                    Bob James
                                    last edited by

                                    @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 πŸ˜†

                                    i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

                                    1 Reply Last reply Reply Quote 0
                                    • jiminy-billy-bobJ Offline
                                      jiminy-billy-bob
                                      last edited by

                                      @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.

                                      25% off Skatter for SketchUcation Premium Members

                                      1 Reply Last reply Reply Quote 0
                                      • jiminy-billy-bobJ Offline
                                        jiminy-billy-bob
                                        last edited by

                                        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...

                                        25% off Skatter for SketchUcation Premium Members

                                        1 Reply Last reply Reply Quote 0
                                        • TIGT Offline
                                          TIG Moderator
                                          last edited by

                                          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) or page.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 ?

                                          TIG

                                          1 Reply Last reply Reply Quote 0
                                          • jiminy-billy-bobJ Offline
                                            jiminy-billy-bob
                                            last edited by

                                            http://i.imgur.com/KJOyOXA.png

                                            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...

                                            25% off Skatter for SketchUcation Premium Members

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement