Results 1 to 5 of 5

Thread: Objects linked in a reactor that delete together AND undo together

  1. #1
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Default Objects linked in a reactor that delete together AND undo together

    I've created code that links objects together in a reactor:

    Code:
    (vl-load-com)
    
    (defun LinkObjects (ObjList / ReactObj)
       (if ObjList
          (progn
             (setq ReactObj (vlr-object-reactor
                                           ObjList
                                           nil
                                           '((:vlr-erased . LinkObj:Delete)
                                             (:vlr-unappended . LinkObj:Delete)
                                            )
                                  )
             );end setq
          (vlr-pers ReactObj);Make the reactor persistent
          );end progn
       );end if
    );end defun
    
    
    (defun LinkObj:Delete (LinkObj ReactObj ParamList / )
       (if (not (vl-position ReactObj *LinkReactorsToRemove*))
          (setq *LinkReactorsToRemove* (cons ReactObj *LinkReactorsToRemove*))
       );end if
    );end defun
    Another snippet sets up a command-reactor
    Code:
    (vlr-command-reactor
       nil
       '((:vlr-commandWillStart . LinkReact:CommandStart)
         (:vlr-commandEnded . LinkReact:CommandEnd))
    )
    
    (defun LinkReact:CommandStart (Reactor CommandList / )
       (setq *LinkReactorsToRemove* nil)
    );end defun
    
    (defun LinkReact:CommandEnd (Reactor CommandList / )
       (cond (*LinkReactorsToRemove*
                (foreach ReactorToRemove *LinkReactorsToRemove*
                   (LinkObj:SafeDelete (vlr-owners ReactorToRemove))
                   );end foreach
                );end *LinkReactorsToRemove* 
       );end conds
       (LinkObj:SafeDeleteGo)
    );end defun
                    
    (defun LinkObj:SafeDelete (ObjList / )
       (foreach Obj ObjList
          (if (and (not (vl-position Obj *LinkSafeToDelete*))
                     (not (vlax-erased-p Obj)))
             (progn
                (vla-put-visible Obj 0)
                (setq *LinkSafeToDelete* (cons Obj *LinkSafeToDelete*))
             );end progn
          );end if
       );end foreach
    );end defun
    
    (defun LinkObj:SafeDeleteGo ( / )
       (if *LinkSafeToDelete*
          (foreach Obj *LinkSafeToDelete*
             (if (not (vlax-erased-p Obj))
                (vla-erase Obj)
             );end if
          );end foreach
       );end if
    );end defun
    Finally, a simple command to create the link...
    Code:
    (defun C:LinkObjects ( / SS SSLen ObjList)
       (if (setq SS (ssget))
          (progn
             (Setq SSLen (sslength SS))
    
             (while (> (Setq SSLEn (1- SSLen)) -1)
                (setq ObjList (cons (vlax-ename->vla-object (ssname SS SSLen)) ObjList))
                );end while
             (if ObjList
                (LinkObjects ObjList)
                );end if
             );end progn
          );end if
       );end defun

    So i can draw a couple of plines, and then run LinkObjects, and they are linked together.

    If I delete one object, then all of the other linked objects will also be deleted.

    However, when I undo, only the object(s) I selected before are un-deleted, though the object reactor still exists and points to all linked objects.

    How do I get all linked objects to undo together?

    Thanks!

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Objects linked in a reactor that delete together AND undo together

    Quote Originally Posted by JaCAD View Post
    How do I get all linked objects to undo together?
    That's a great question, for a very ambitious task... I haven't tested this yet, but in the spirit of 'management of expectations', I'm not entirely sure that this is possible for the LISP API.

    [Edit] - You did try adding *UndoMarks?

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Default Re: Objects linked in a reactor that delete together AND undo together

    I have not tried *UndoMarks.

    It's really weird, I could have sworn that I had this working, with the same code, a couple of weeks ago.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Objects linked in a reactor that delete together AND undo together

    Not sure if this will be of any help here, but for reference, here are some links regarding the StartUndoMark, and EndUndoMark Methods.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Default Re: Objects linked in a reactor that delete together AND undo together

    I added the StartUndoMark to the CommandStart reactor, and the EndUndoMark to the CommandEnd reactor, and a new CommandCancelled reactor.

    It now seems that I cannot undo even 1 object. I get the following message:
    Quote Originally Posted by AutoCAD
    Command: u
    Start of Group encountered.
    Must enter UNDO END to go back further.

Similar Threads

  1. Replies: 4
    Last Post: 2013-08-31, 01:22 PM
  2. Delete linked DWG
    By matt__w in forum Revit MEP - General
    Replies: 4
    Last Post: 2010-08-11, 06:46 PM
  3. cannot delete linked DWF
    By Ning Zhou in forum Revit - API
    Replies: 0
    Last Post: 2010-07-28, 08:10 PM
  4. Replies: 1
    Last Post: 2009-08-14, 01:05 PM
  5. AutoCAD slow to UNDO objects
    By GreyHippo in forum AutoCAD General
    Replies: 3
    Last Post: 2005-10-19, 09:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •