sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Commit working like undo command

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 259 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.
    • B Offline
      bizello
      last edited by

      Hi,
      I trying to use commit to do some like "undo" command. I´ve found something in the net and one script worked, but others...
      The code below works, you can activate only a "commit line" and the face is erased like you want, full control.

      
      def desenha1
      modelo = Sketchup.active_model
      entities = modelo.active_entities
      pt = []
      pt[0] = [0,0,0]
      pt[1] = [5,0,0]
      pt[2] = [5,5,0]
      pt[3] = [0,5,0]
      abertura = entities.add_face pt
      end
      
      def desenha2
      modelo = Sketchup.active_model
      entities = modelo.active_entities
      pt = []
      pt[0] = [0,6,0]
      pt[1] = [5,6,0]
      pt[2] = [5,10,0]
      pt[3] = [0,10,0]
      abertura = entities.add_face pt
      end
      
      def desenha3
      modelo = Sketchup.active_model
      entities = modelo.active_entities
      pt = []
      pt[0] = [6,0,0]
      pt[1] = [10,0,0]
      pt[2] = [10,4,0]
      pt[3] = [6,4,0]
      abertura = entities.add_face pt
      end
      
      #Sketchup.active_model.start_operation("Undo")
      desenha1
      #Sketchup.active_model.start_operation("Undo")
      desenha2
      Sketchup.active_model.start_operation("Undo")
      desenha3
      
      resposta = UI.messagebox "Erase face?", MB_YESNO
      
      if resposta == 6 then
      Sketchup.active_model.commit_operation(a)
      else
      UI.messagebox "So stay."
      end
      
      

      But I have a part of the another code that doesn't work, I think you don't need all the code, so I'm sending the part with "commit" don't working, the code below:

      
      model = Sketchup.active_model
      Sketchup.active_model.start_operation("undo")
      entities = model.active_entities
      abertura = entities.add_face ptabs
      rayt=modelo.raytest(ptabs[0], abertura .normal.reverse)
      ptabs_rev=rayt[0]
      espess=ptabs[0].distance(ptabs_rev)
      abertura.pushpull(-espess)
      
      abeyesno = UI.messagebox "A posição da abertura na parede está correta?
      Proceder com o cadastro no Banco de Dados?", MB_YESNO
      
      if abeyesno == 6 then #yes
         cadaberturas(ptabs, espess, cod_arq_atual[0], cod_arq_atual[1], localiza)
        else
         Sketchup.active_model.commit_operation(abertura)
      end
      
      

      I dont' know why the second code doesn't work. I can't see what is wrong.
      If you help me, very thanks.

      Sérgio.

      PS. I need to answer like I solved the my another topis called "edges, angle and rectangle triangle". I'll to write all the problem and describe my solution.

      Sérgio A.Bizello

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

        Do not name each operation with the same string "Undo"...

        give each a unique name "Draw Face 1", "Draw Face 2", etc.

        It's best to wrap each operation in a begin ... rescue ... end block and have an abort_operation call in the rescue clause. (methods are also begin .. rescue .. end blocks, where the def *methodname* takes the place of the begin keyword.)

        modelo = Sketchup.active_model
        begin
          modelo.start_operation("Draw Wall 1")
        
          # ... draw entities code ...
        
          modelo.commit_operation
        
          msg = "A posição da abertura na parede está correta?\n"
          msg<< "Proceder com o cadastro no Banco de Dados?"
          abeyesno = UI.messagebox( msg, MB_YESNO )
        
          if abeyesno == 6 then #yes
            cadaberturas(ptabs, espess, cod_arq_atual[0], cod_arq_atual[1], localiza)
          else
            Sketchup.send_action("editUndo;")
          end
        
        rescue
          modelo.abort_operation
          UI.messagebox("Error Adding Enities!")
        end
        

        Edit: corrected newline character in messagebox string.

        commit_operation and abort_operation do not have arguments:

        modelo.method(:commit_operation).arity

        0

        modelo.method(:abort_operation).arity

        0

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • B Offline
          bizello
          last edited by

          Hi Dan,

          Thank you. Its works now.

          I think understand how using commit.
          Thanks to show how you do your messages in a script. I liked.
          I had some asks about send_action and abort but I saw how they works.
          So, I edit this post.
          Thank you Dan.

          SérgioBizello

          Sérgio A.Bizello

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

            Note that start_operation cannot be nested. Doing a new start_operation after another will commit the first.

            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