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

    Model Operation blockform methods.

    Scheduled Pinned Locked Moved Developers' Forum
    24 Posts 4 Posters 2.0k Views 4 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      Weird...

      If you specify an empty string, as the name of the first operation, in a set which the followers are transparent,... the name in the menu is: "Undo Macro"

      I'm not here much anymore.

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

        I pushed several changes today.
        https://bitbucket.org/dan_rathbun/sae-operation-class

        Works much more like it should:

        • call/ commit method can take an array of values to pass into the block.
        • class method ::raise_errors() and ::raise_errors=() to control whether exceptions are raised. (This will likely be used for debugging mostly.)
        • class method ::redo wrapper for Sketchup.send_action('editRedo:')
        • class method ::undo wrapper for Sketchup.send_action('editUndo:')
        • an OpStat object is passed into the block, holding information about the operation itself that might be useful. (This was done instead of passing a direct reference to the operation itself, which would open the door to dangerous things, like calling commit from within the block and causing a vicious loop that would probably cause a stack overflow.)
        • onError() {|opStat,model,exception| ... code block ... }

        Allows custom handling of errors (ie, translate error messages into Spanish, etc.)

        • onSuccess() {|opStat,model,results| ... code block ... }

        Allows custom handling if everything goes well. (ie, prompt the user to save something, etc.)

        I'm not here much anymore.

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

          Here's an example of using the one-shot block form class wrapper method:

          1) Say you write a simple "Add Face" plugin with no operations (because either you did not know about them being a newbie, or you just wished to get it working first and polish it later.)

          So you have code that looks like:

          require('sketchup.rb')
          
          module Author ### <-- this would actually be your toplevel namespace
          
            module FaceAdder
            
              class << self
                private
                def add_face
                  #
                  mdl = Sketchup.active_model
                  depth = 10
                  width = 10
                  pts = []
                  pts[0] = [0, 0, 0]
                  pts[1] = [width, 0, 0]
                  pts[2] = [width, depth, 0]
                  pts[3] = [0, depth, 0]
                  # Add the face to the entities in the model
                  grp = mdl.entities.add_group()
                  face = grp.entities.add_face( pts )
                  return grp
                  #
                end
              end # proxy class
              
              unless file_loaded?(File.basename(__FILE__))
                UI.menu('Plugins').add_item('FaceAdder') {
                  add_face()
                }
                file_loaded(File.basename(__FILE__))
              end
          
            end # module FaceAdder
          end # module
          
          

          2) Now you want the the entire command to be one Undo operation.

          You can modify the menu item proc, like this:

                UI.menu('Plugins').add_item('FaceAdder') {
                  begin
                    require('sae/operation.rb')
                  rescue LoadError
                    add_face() # User does not have file.
                  else
                    SAE.operation('Add Face') { add_face() }
                  end
                }
          
          

          In this example, the "Undo" name that will appear in the menu (or the popup tooltip for the undo button on the toolbar,) is specified as "Add Face". All other options will use the defaults, .. ie, the 2nd model argument will default to the active_model, the 3rd argument will be set to disable the UI during the operation's block execution, and the operation will not be hidden.

          Putting it all together, the example file, would look like:

          require('sketchup.rb')
          
          module Author ### <-- this would actually be your toplevel namespace
          
            module FaceAdder
            
              class << self
                private
                def add_face
                  #
                  mdl = Sketchup.active_model
                  depth = 10
                  width = 10
                  pts = []
                  pts[0] = [0, 0, 0]
                  pts[1] = [width, 0, 0]
                  pts[2] = [width, depth, 0]
                  pts[3] = [0, depth, 0]
                  # Add the face to the entities in the model
                  grp = mdl.entities.add_group()
                  face = grp.entities.add_face( pts )
                  return grp
                  #
                end
              end # proxy class
              
              unless file_loaded?(File.basename(__FILE__))
                UI.menu('Plugins').add_item('FaceAdder') {
                  begin
                    require('sae/operation.rb')
                  rescue LoadError
                    add_face() # User does not have file.
                  else
                    SAE.operation('Add Face') { add_face() }
                  end
                }
                file_loaded(File.basename(__FILE__))
              end
          
            end # module FaceAdder
          end # module
          
          

          If this kind of method were to be added into the API, it would likely be an instance method of Sketchup::Model, which would not need the 2nd model argument.

          Of course there could also be a model "flexible" duplicate class method (like I've implemented it,) that does take a model arg, which would either be a module method Sketchup.operation(), or a class method like Sketchup::Model.operation()

          Thoughts ??

          I'm not here much anymore.

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

            Putting this on the back burner until I get some feedback.

            I'm not here much anymore.

            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