sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Ruby, Undo Stack and dynamic components

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 1.5k Views 3 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.
    • danielbowringD Offline
      danielbowring
      last edited by

      Hey,

      I'm working with using dynamic components in ruby. I'm able to set attributes and have them applied as such

      ent.set_attribute(dict, key, value)
      # ...
      $dc_observers.get_latest_class.redraw_with_undo(ent)
      

      However, doing so fills the undo stack with "Properties" and "redraw" operations, which is interfering with my own operation (which I start before the DC's are created and commit after the last redraw), as such

      def some_func()
          #...
          Sketchup;;active_model.start_operation 'My Operation'
          create_ent()
          Sketchup;;active_model.commit_operation
      end
      #...
      def create_ent()
          ent = Sketchup;;active_model.entities.add_instance(definition, transformation)
          ent.set_attribute 'dynamic_attributes', 'some_key', 'some_value' # adds "Properties" to the undo stack
          #...
          $dc_observers.get_latest_class.redraw_with_undo(ent) # adds "Redraw" to the undo stack
      end
      

      How can I ensure that my operation is the only one that appears in the undo stack, so that a single undo operation will remove all the ent, etc?

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

        Have you explored the extra arguments to start_operation() ??

        I'm not here much anymore.

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

          instead of redraw_with_undo( entity, progress_bar_visible=true )
          you can also use this:

          redraw( entity, progress_bar_visible=true, is_recursive_call=false )

          example in your module:

          module Bowring
          
            def self.dc_redraw( ent, pbar_visible=true, undo=false )
              #
              ldc = $dc_observers.get_latest_class()
              #
              if undo
                ldc.method(;redraw_with_undo).call( ent, pbar_visible )
              else
                ldc.determine_movetool_behaviors(ent)
                DCProgressBar;;clear()
                ldc.method(;redraw).call( ent, pbar_visible )
                DCProgressBar;;clear()
                ldc.refresh_dialogs()
              end
              #
            rescue TypeError => e
              # suppress nil to float conversion error that happens
              # when redraw is called directly with true 2nd arg.
            end #def
          
          end #module
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • danielbowringD Offline
            danielbowring
            last edited by

            @dan rathbun said:

            @dan rathbun said:

            Have you explored the extra arguments to start_operation() ??

            instead of redraw_with_undo( entity, progress_bar_visible=true )
            you can also use this:

            redraw( entity, progress_bar_visible=true, is_recursive_call=false )

            Combination of these was indeed the solution - thanks again πŸ˜„

            1 Reply Last reply Reply Quote 0
            • danielbowringD Offline
              danielbowring
              last edited by

              Another question on the undo stack, is it possible to prevent operations from appearing in the undo stack at all? To basically have transparent actions that are never added to the stack?

              In certain cases I have to show/hide entities during an input stage, and that clutters the undo stack. It's possible to move them into one operation, but the stack looks something like

              
              Operation 1
              hide/show-operations
              Operation 2
              
              

              Which adds an unnecessary undo step (as I undo all the operations performed in the ruby code).

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                You could try with the transparency flags of .start_operation .

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

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

                Advertisement