Author Topic: Undo is not working in my routine  (Read 3658 times)

0 Members and 1 Guest are viewing this topic.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Undo is not working in my routine
« on: March 07, 2011, 11:37:43 AM »
Hello .

Here is a routine that I have just finished writing it , but the start undo besides end undo functions are not working with it after
invoking the routine .

Any thoughts please ?

Code: [Select]
(defun c:TesT (/ *error* acdoc Blocks)
; Tharwat 07. 03. 2011
  (vl-load-com)
  (defun *error* (msg)
    (and (vla-EndUndoMark acdoc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
    )
    (princ)
  )
  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark acdoc)
  (vlax-for Blocks
            (vla-get-blocks
              (setq
                acdoc (vla-get-activedocument (vlax-get-acad-object))
              )
            )
    (if (and (eq (vla-get-isXref Blocks) :vlax-false)
             (eq (vla-get-isLayout Blocks) :vlax-false)
        )
      (vlax-for vl Blocks
        (vla-put-color vl 256)
      )
    )
  )
  (vla-regen acdoc acActiveViewport)
  (vla-EndUndoMark acdoc)
   (princ)
)

Thanks.

Tharwat

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #1 on: March 07, 2011, 12:10:57 PM »
Actually the undo is working , but I've got to regenall after the undo invokes .

That's odd isn't it ?  :-(

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Undo is not working in my routine
« Reply #2 on: March 07, 2011, 01:33:31 PM »
Actually the undo is working , but I've got to regenall after the undo invokes .

That's odd isn't it ?  :-(
Not really. You had to execute a regen to display your changes.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #3 on: March 07, 2011, 01:40:17 PM »
Actually the undo is working , but I've got to regenall after the undo invokes .

That's odd isn't it ?  :-(
Not really. You had to execute a regen to display your changes.

Right , So it's normal to regen after undoing .

Thanks

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Undo is not working in my routine
« Reply #4 on: March 07, 2011, 02:30:24 PM »
Actually the undo is working , but I've got to regenall after the undo invokes .

That's odd isn't it ?  :-(
Not really. You had to execute a regen to display your changes.

Right , So it's normal to regen after undoing .

Thanks
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #5 on: March 08, 2011, 02:46:37 AM »
OK, the same issue but with single selection set .

This routine is not responding as needed .  :realmad:

So any guidance ?

Code: [Select]
(defun c:TesT (/ acdoc ss )
; Tharwat 07. 03. 2011
  (vl-load-com)
  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
    (vlax-for Blocks
              (vla-item (vla-get-blocks acdoc) (vlax-ename->vla-object (ssname ss 0)))
      (if (and (eq (vla-get-isXref Blocks) :vlax-false)
               (eq (vla-get-isLayout Blocks) :vlax-false)
          )
        (vlax-for vl Blocks
          (vla-put-color vl 256)
        )))
    (princ)
  )
  (vla-regen acdoc acActiveViewport)
  (princ)
)

Thanks.

Tharwat


pBe

  • Bull Frog
  • Posts: 402
Re: Undo is not working in my routine
« Reply #6 on: March 08, 2011, 07:42:43 AM »
Code: [Select]
(defun c:TesT (/ acdoc ss )
; Tharwat 07. 03. 2011
  (vl-load-com)
  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
    (vlax-for Blocks
              (vla-item (vla-get-blocks acdoc) [color=blue](vla-get-effectivename [/color] (vlax-ename->vla-object (ssname ss 0))))
          (vla-put-color blocks 256)
        )
    (princ)
  )
  (vla-regen acdoc acActiveViewport)
  (princ)
)

I could have sworn this code was resolved at CADTUTOR forum Tharwat .. anyhoo , remove some unecessary codes on your post, unless you have a block/xref inside your block, but thats another matter altogether...  :-)
« Last Edit: March 08, 2011, 07:58:27 AM by pBe »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #7 on: March 08, 2011, 08:15:38 AM »
I could have sworn this code was resolved at CADTUTOR forum Tharwat .. anyhoo , remove some unecessary codes on
your post, unless you have a block/xref inside your block, but thats another matter altogether...  :-)

Thank you for that clarification .

And I do not remember if these codes were resolved before in Cadtutor , where I a part of the thread ? :|

If there were , I would not ask . :wink:

Appreciated a lot pBe.

AIberto

  • Guest
Re: Undo is not working in my routine
« Reply #8 on: April 26, 2016, 08:14:21 AM »
@Tharwat

Hi Tharwat.

Have you find ways to solve this problem yet?  REGEN after UNDO  . use reactor  ?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Undo is not working in my routine
« Reply #9 on: April 26, 2016, 08:50:57 AM »
@Tharwat

Hi Tharwat.

Have you find ways to solve this problem yet?  REGEN after UNDO  . use reactor  ?
Look into VLA-UPDATE.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #10 on: April 26, 2016, 08:57:57 AM »
@Tharwat

Hi Tharwat.

Have you find ways to solve this problem yet?  REGEN after UNDO  . use reactor  ?

Hi,
I did not solve that issue in that time but I think now I can write a reactor function to regen the document if a user called the undo command and of course if the function Undoreactor-on is already invoked.

Try the following:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:UndoReactor-on nil
  2.   ;; Tharwat 26.Apr.2016        ;;
  3.   (if (vl-some '(lambda (r) (= (vlr-data r) "undo:me"))
  4.                (cdar (vlr-reactors :vlr-command-reactor))
  5.                )
  6.     (alert "Reactor is already running !")
  7.       "undo:me"
  8.       '((:vlr-commandEnded . UndoMe))
  9.       )
  10.     )
  11.   (princ)
  12.   )
  13. ;;                                              ;;
  14. (defun c:UndoReactor-off nil
  15.   (if (vl-some
  16.         '(lambda (r) (and (= (vlr-data r) "undo:me") (vlr-remove r)))
  17.         )
  18.     (alert "Reactor is Deactivated now !")
  19.     (princ "\nReactor in not yet activated !")
  20.     )
  21.   (princ)
  22.   )
  23. ;;                                              ;;
  24. (defun Undome (r c)
  25.   (if (and (eq (vlr-data r) "undo:me")
  26.            (wcmatch (strcase (car c)) "UNDO,U")
  27.            )
  28.     (progn
  29.       (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
  30.       (princ "\nRegen generated by a reactor ...")
  31.       )
  32.     )
  33.   (princ)
  34.   )
  35.  

AIberto

  • Guest
Re: Undo is not working in my routine
« Reply #11 on: April 26, 2016, 11:59:04 AM »
Hip, Hip Hurray  .A great  reactor function . Thank you Tharwat.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Undo is not working in my routine
« Reply #12 on: April 26, 2016, 12:37:20 PM »
Hip, Hip Hurray  .A great  reactor function . Thank you Tharwat.

You are welcome AIberto.