Adding and undo capability to a text edit command

Discussion in 'AutoCAD' started by T.Willey, May 25, 2004.

  1. T.Willey

    T.Willey Guest

    I have a lot of text editing to do, text and attributes, so I made this routine. It works great now, but I wanted to add an undo capability, but I'm not sure how to do it so that it could set back more than one step.

    Thanks

    (defun c:ae(/ ob1 ob2 ob3 tx1 tx2)

    (command "undo" "group")
    (setvar "errno" 0)
    (while (/= (getvar "errno") 52)
    (while (setq ob1 (nentselp "\nSelect attribute or text to edit <Enter to exit>: "))
    (if (or (not (cadddr ob1)) (> (vl-list-length (cadddr ob1)) 1))
    (progn
    (setq ob2 (entget (car ob1)))
    (setq ob4 (cdr (assoc 0 ob2)))
    (if (or (= ob4 "ATTRIB") (= ob4 "TEXT") (= ob4 "MTEXT"))
    (progn
    (cond
    ((= ob4 "MTEXT")
    (command "ddedit" ob1 "")
    )
    ((or (= ob4 "ATTRIB") (= ob4 "TEXT"))
    (setq tx1 (cdr (assoc 1 ob2)))
    (ae-dia); this is my dialog box just to make it look like ddedit
    (setq ob3 (subst (cons 1 tx2) (cons 1 tx1) ob2))
    (entmod ob3)
    (entupd (cdr (assoc -1 ob3)))
    )
    ); end cond
    ); end progn
    (prompt "\n No attribute or text selected: ")
    ); end if
    );end progn
    (prompt "\n Nothing editable selected: ")
    ); end if
    ); end while
    ); end while
    (command "undo" "end")
    (princ)
    )

    Any ideas are appreciated.

    Tim
     
    T.Willey, May 25, 2004
    #1
  2. T.Willey

    T.Willey Guest

    Never mind. I got it to work here is the final routine (minus the .dcl file) that works. If anyone wants to look at it to see if there is room to improve, be my guest, all comments accepted.


    (defun c:ae(/ ob1 ob2 ob3 tx1 tx2 tlst1 tlst2 olst1 olst2 uob1 uob2 lng1)

    (command "undo" "group")
    (setvar "errno" 0)
    (setq tlst1 nil
    olst1 nil
    ob1 nil
    )
    (while (and (/= (getvar "errno") 52) (not ob1))
    (initget "U")
    (setq ob1 (nentselp "\nSelect attribute or text to edit or \"U\" to undo <Enter to exit>: "))
    (if (= ob1 "U")
    (progn
    (ae-undo)
    (setq ob1 nil)
    ); end progn
    (progn
    (if ob1
    (progn
    (if (or (not (cadddr ob1)) (> (vl-list-length (cadddr ob1)) 1))
    (progn
    (setq ob2 (entget (car ob1)))
    (setq ob4 (cdr (assoc 0 ob2)))
    (if (or (= ob4 "ATTRIB") (= ob4 "TEXT") (= ob4 "MTEXT"))
    (progn
    (cond
    ((= ob4 "MTEXT")
    (command "ddedit" ob1 "")
    )
    ((or (= ob4 "ATTRIB") (= ob4 "TEXT"))
    (setq tx1 (cdr (assoc 1 ob2)))
    (Setq tlst1 (append tlst1 (list (cdr (assoc 1 ob2)))))
    (setq olst1 (append olst1 (list (cdr (assoc -1 ob2)))))
    (ae-dia)
    (setq ob3 (subst (cons 1 tx2) (cons 1 tx1) ob2))
    (entmod ob3)
    (entupd (cdr (assoc -1 ob3)))
    )
    ); end cond
    ); end progn
    (prompt "\n No attribute or text selected: ")
    ); end if
    ); end progn
    ); end if
    );end progn
    (prompt "\n Nothing editable selected: ")
    ); end if
    (setq ob1 nil)
    ); end progn
    ); end if
    ); end while
    (command "undo" "end")
    (princ)
    )


    (defun ae-dia()

    (setq op1 (load_dialog "AE.dcl"))
    (if (not (new_dialog "AttEdit" op1))
    (exit)
    )

    (set_tile "tx2" tx1)
    (mode_tile "tx2" 2)
    (action_tile "accept"
    "(progn
    (setq tx2 (get_tile \"tx2\"))
    (done_dialog 1)
    )"
    )
    (start_dialog)
    )


    (defun ae-undo()

    (if tlst1
    (progn
    (setq lng1 (vl-list-length olst1))
    (setq tlst2 (nth (1- lng1) tlst1))
    (setq olst2 (nth (1- lng1) olst1))
    (setq uob1 (entget olst2))
    (setq uob2 (subst (cons 1 tlst2) (assoc 1 uob1) uob1))
    (entmod uob2)
    (entupd (cdr (assoc -1 uob2)))
    (setq tlst1 (vl-remove tlst2 tlst1))
    (setq olst1 (vl-remove olst2 olst1))
    )
    (prompt "\n Everything has be undone. ")
    )

    )

    Tim
     
    T.Willey, May 25, 2004
    #2
  3. T.Willey

    T.Willey Guest

    I ran into one problem. When I select the same text more than once and try and undo it, it crashes.

    Any help with these feature is appreciated.

    Thanks,
    Tim
     
    T.Willey, May 26, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.