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.
    • TIGT Online
      TIG Moderator
      last edited by

      I think I see the difference πŸ˜•

      So the layers change in your dialog to match the Scene-tab's [or the current manually setup] layers.
      But when changing a Scene-tab the 'group' values are ignored...
      So I see a couple of ways to resolve this without having to 'auto-update' the scene's layers to match the dialog and thereby confuse the user...

      You get/set an attribute array attached to the model for the 'Groups' and their 'Layers' contents [with visibility flags?].
      You can also get/set an attribute array of Groups [with on/off flags] with each Scene [page].

      So now you have access to the permutations.
      You manually make or update a scene-tab [either manually or through the tool itself], the current state of your tool's data, and the current Groups is then set as a 'Groups' attribute with that Scene [page].

      Later a scene-tab changes, the pages.selected_page gets its reference, and lets that you get its Groups attribute that the scene has had set earlier, and it then updates the tool's data saved in the model attribute - available even when the dialog is inactive, but read in when it next opens... The change of layers comes from the scene-tab, and is reflected in the tool's layer settings too...

      You change the settings in the tool's dialog, these are dynamically saved to the model's attributes as Groups and their Layers. Only when the scene-tab is updated does that data get read to set the Groups attribute for the page.

      One issue you need to address is the 'making of new layers'.
      By SketchUp's default these are visible in all new scenes [auto-updating the scenes' layer lists], this is a know bugbear.
      It is possible to set a flag for a layer as you make it, which then stops this behavior http://sketchup.com/intl/en/developer/docs/ourdoc/layer.php#page_behavior

      I am sure this scene0tab auto-update issue can be circumvented with some careful planning πŸ˜•

      TIG

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

        @tig said:

        You manually make or update a scene-tab [either manually or through the tool itself], the current state of your tool's data, and the current Groups is then set as a 'Groups' attribute with that Scene [page].

        Sure, that's what I'm trying to acheive. But the problem is how to detect manual updates ?

        Everything else is up and running. I just need to find a way to detect a page update, otherwise everything gets messed up. I wouldn't know when to save the tool's data so that it matches the layers state when the user comes back to this page.

        25% off Skatter for SketchUcation Premium Members

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

          So we go full circle πŸ˜’

          A page is an entity.
          So can you an an entity_observer to each page, that fires onChangeEntity ?
          Do nothing to modify the page in the response - we are changing your tool...

          If the page changes on an 'update' does such an observer fire ? πŸ˜•

          TIG

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

            @tig said:

            If the page changes on an 'update' does such an observer fire ? πŸ˜•

            Nope ^^

            @dan rathbun said:

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

            25% off Skatter for SketchUcation Premium Members

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

              We go round in circles... πŸ˜’

              Although page and layer are entities we cannot get valid/useful entity-observer results...
              The layers and pages observer do not spot 'active/selected' changes.
              A model-observer only spots undo-able transactions.
              A tools-observer do not see page-update events.

              You could set up a UI timer to poll the pages, and get just the pages.selected_page [every few seconds ?] and save a @array of its '.layers' [or perhaps a hash? - perhaps using 'names' rather than id's as they will then be sortable?]: it compares the @array with the last time it saved this - @array_previous [cloned from the @array] - then if it mismatches it triggers your tool to redo the current layers based on the selected_page.layers [which returns an array of the page's non-visible layers]. This will work as the selected_page changes too, if the layers mismatch it updates the dialog...

              You only need to set/compare the layer records for a page that is selected.
              A user updating a non-selected page is coped with when that page becomes selected and your tool updates the layer set as it spots the change ?

              πŸ˜•
              I'll sleep on it...
              Any other ideas ??

              TIG

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

                I wondered about a timer-based solution, but isn't it too heavy for performance ?

                25% off Skatter for SketchUcation Premium Members

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

                  I suggest that you try it and see...
                  If the only tool we have is a hammer, watch out screws!

                  A UI timer should run in parallel with other processes...
                  Your UI timer loop can kick in at say every 5 seconds - and it is stopped when the dialog closes - the newly opened dialog refreshes from the current settings anyway, and starts a new timer...
                  It is only collecting the pages.selected_page.layers [perhaps as sorted layer.names for easier comparison ?] and then comparing those with the list it got the previous time [using a array == @array ?]. It does nothing if there is a match, but on a mismatch it refreshes your tool's layer lists ?
                  Some example code ideas:

                  ### when the dialog first opens and is to be 'populated'...
                  @timer=UI.start_timer(5, true)
                    @array=[] unless @array
                    array=Sketchup.active_model.pages.selected_page.layers.collect{|e|e.name}.sort
                    unless array==@array
                      ### update your tool's dialog's layer list here...
                    end
                    @array=array.clone
                  }
                  ### ...
                  ### elsewhere in dialog code...
                  dialog.set_on_close{
                    UI.stop_timer(@timer)
                  }
                  ###
                  
                  

                  I know it's not ideal, but it might be the best you have ?

                  If it causes too many issues then we are no worse off ?

                  TIG

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

                    Got it fully working !
                    Thanks TIG for taking a deep look at this πŸ˜‰

                    25% off Skatter for SketchUcation Premium Members

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

                      Well, actually it needs some tweaking ^^

                      25% off Skatter for SketchUcation Premium Members

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

                        πŸ˜’

                        πŸ˜‰

                        TIG

                        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