Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 1 of 3 (187 Views)
Accepted Solution

Verticale Xline with undo

187 Views, 2 Replies
01-03-2014 06:46 AM

hi,

 

So i have now 

 

(defun C:VV (/ *error* inspt done)
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command); cancel Insert command, then
    (command "_.layerp")
  ); defun -- *error*
  (command "_.LAYER" "_Set" "4031.Niet.Afdrukbaar" "")
  (while (not done)
    (command "_.xline" "V"); leave in command
    (cond ; at insertion-point prompt
      ((setq inspt (getpoint "\nInsertion point or <exit>: ")); point if picked, nil if Enter
        (command inspt "" "" ""); finish Insertion
      ); end picked-a-point condition
      (T ; on Enter/space at insertion-point prompt
        (command); cancel Insert
        (setq done T); stop (while) loop
      ); end exit condition
    ); cond
  ); while
  (command "_.layerp")
); defun

 

But i need a lisp, that put a verticale Xline and also make it possible to undo one of the "loop"xlines. So in normal terms, i would put xline, enter, then copy last object, the xline at the base point and then drag it around. Copy make it possible to undo in the command. The code above was a little try so it could be that there are some bugs in it :smileyhappy:.

 

Shout away.

 

Thanks

 


Subje wrote:

....

But i need a lisp, that put a verticale Xline and also make it possible to undo one of the "loop"xlines. So in normal terms, i would put xline, enter, then copy last object, the xline at the base point and then drag it around. Copy make it possible to undo in the command. The code above was a little try so it could be that there are some bugs in it :smileyhappy:.

....


Several things about that code are left-overs from a multiple-Insert routine [which I think I wrote], and are not relevant to copying Xlines around.  I think if you want to be able to Undo individual added Xlines, then each needs to be put there by its own separate Copy command, rather than with one Copy command and the Multiple option.  Borrowing from another routine of mine for the individual-Undo-along-the-way aspect, I patched together the following, which seems to do what you're describing, in limited testing:

 

(defun C:VV (/ *error* pt1 xl n pt done)
  (defun *error* (errmsg); Escape at next-Xline location prompt
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if

    (command "_.layerp")

    (princ)
  ); defun -- *error*
  (command
    "_.LAYER" "_thaw" "4031.Niet.Afdrukbaar" "_make" "4031.Niet.Afdrukbaar" ""
      ;; [in case it's frozen, or doesn't yet exist]
    "_.xline" "_ver" (setq pt1 (getpoint)) "" ; draw first one
  ); command
  (setq
    xl (entlast); the first one drawn
    n 0 ; for Undo counter below
  ); setq
  (while (not done)
    (if (> n 0) (initget "Undo")); Undo option only if things to undo
    (setq pt
      (getpoint pt1 ; rubber-banded from first one
        (strcat
          "\nNext Xline location, or "
          (if (> n 0) "[Undo] " ""); Undo option only if things to undo
          "<exit>: "
        ); strcat
      ); getpoint
    ); setq
    (cond ; overall point-selection or Undo option
      ((= pt "Undo")
        (setq n (1- n)); increment counter downward
        (command "_u"); remove last-added Xline
      ); Undo condition
      (pt ; picked a point
        (command "_.copy" xl "" pt1 pt)
        (setq n (1+ n)); increment counter upward
      ); picked-a-point condition
      (T ; Enter/space for <exit> default [nil return]
        (setq done T); stop (while) loop
      ); end exit condition
    ); cond
  ); while
  (command "_.layerp")

  (princ)
); defun

 

It could use further enhancements [maybe Unlock the Layer just in case, command-echo suppression for parts of it, etc.].

*Expert Elite*
Kent1Cooper
Posts: 5,615
Registered: ‎09-13-2004
Message 2 of 3 (165 Views)

Re: Verticale Xline with undo

01-03-2014 08:30 AM in reply to: Subje

Subje wrote:

....

But i need a lisp, that put a verticale Xline and also make it possible to undo one of the "loop"xlines. So in normal terms, i would put xline, enter, then copy last object, the xline at the base point and then drag it around. Copy make it possible to undo in the command. The code above was a little try so it could be that there are some bugs in it :smileyhappy:.

....


Several things about that code are left-overs from a multiple-Insert routine [which I think I wrote], and are not relevant to copying Xlines around.  I think if you want to be able to Undo individual added Xlines, then each needs to be put there by its own separate Copy command, rather than with one Copy command and the Multiple option.  Borrowing from another routine of mine for the individual-Undo-along-the-way aspect, I patched together the following, which seems to do what you're describing, in limited testing:

 

(defun C:VV (/ *error* pt1 xl n pt done)
  (defun *error* (errmsg); Escape at next-Xline location prompt
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if

    (command "_.layerp")

    (princ)
  ); defun -- *error*
  (command
    "_.LAYER" "_thaw" "4031.Niet.Afdrukbaar" "_make" "4031.Niet.Afdrukbaar" ""
      ;; [in case it's frozen, or doesn't yet exist]
    "_.xline" "_ver" (setq pt1 (getpoint)) "" ; draw first one
  ); command
  (setq
    xl (entlast); the first one drawn
    n 0 ; for Undo counter below
  ); setq
  (while (not done)
    (if (> n 0) (initget "Undo")); Undo option only if things to undo
    (setq pt
      (getpoint pt1 ; rubber-banded from first one
        (strcat
          "\nNext Xline location, or "
          (if (> n 0) "[Undo] " ""); Undo option only if things to undo
          "<exit>: "
        ); strcat
      ); getpoint
    ); setq
    (cond ; overall point-selection or Undo option
      ((= pt "Undo")
        (setq n (1- n)); increment counter downward
        (command "_u"); remove last-added Xline
      ); Undo condition
      (pt ; picked a point
        (command "_.copy" xl "" pt1 pt)
        (setq n (1+ n)); increment counter upward
      ); picked-a-point condition
      (T ; Enter/space for <exit> default [nil return]
        (setq done T); stop (while) loop
      ); end exit condition
    ); cond
  ); while
  (command "_.layerp")

  (princ)
); defun

 

It could use further enhancements [maybe Unlock the Layer just in case, command-echo suppression for parts of it, etc.].

Kent Cooper
Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 3 of 3 (131 Views)

Re: Verticale Xline with undo

01-05-2014 11:37 PM in reply to: Kent1Cooper

Works fine for me. and yes it was from that insert command, told myself i could manage to make one on my own, but that reality is far away it seems.

Thanks Kent,flawless as always.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.