Commit working like undo command
-
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." endBut 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) endI 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.
-
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...endblock and have an abort_operation call in therescueclause. (methods are alsobegin..rescue..endblocks, where thedef *methodname*takes the place of thebeginkeyword.)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!") endEdit: corrected newline character in messagebox string.
commit_operationandabort_operationdo not have arguments:modelo.method(:commit_operation).arity0
modelo.method(:abort_operation).arity0
-
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
-
Note that
start_operationcannot be nested. Doing a newstart_operationafter another will commit the first.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement