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." 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.
-
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 therescue
clause. (methods are alsobegin
..rescue
..end
blocks, where thedef *methodname*
takes the place of thebegin
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
andabort_operation
do not have arguments:modelo.method(:commit_operation).arity
0
modelo.method(:abort_operation).arity
0
-
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_operation
cannot be nested. Doing a newstart_operation
after another will commit the first.
Advertisement