Jump to content

Recommended Posts

Posted

I have another question regarding this routine.

This routine works perfect and ends perfect when I press "ESCAPE"

But it won't end when I press "ENTER"

Is there some code I need to the 4th last line?

(defun c:conlob (/ *error* Pt1 Pt2 obline)
  (defun *error* (x)
    (resetoldvar)
    (princ "\n*Cancel*")
    )
  (savevartoold) (constructionlayer)
    (setq Pt1 (getpoint "\nPick First Point:")
          Pt2 (getpoint Pt1 "\nPick Second Point:"))
    (command "_xline" Pt1 Pt2 "")
    (setq obline (entlast))
   (while 1
   (command "_copy" obline "" Pt2 pause (command)))
  (resetoldvar)
 (princ)
)

Regards

Tony

Posted (edited)

You may want to look into (exit) or (quit).  A lot of folks are totally against it.

 

Also

(if (setq pt1 (getpoint "\nPick 1st Point:   "))
    (progn
   .....
))

 

Could be added

 

Edited by David Bethel
Posted

Thanks David

 

I'm not sure what you mean by EXIT & QUIT

Posted

I understand those 2 commands, but I don't want to just add either of them in a line because the copy is on going and I might want to do 50 copies of that line and then I want to press "Escape" or "Enter" to exit the program.

I think the (exit) and (quit) need to be added into a WHILE command

In other words let me keep copying until I want to stop and then let me out of this program by hitting either the "Escape" or "Enter" keys

 

Regards

 

Tony

Posted

You currently have an infinite loop: the expression (while 1 ...) will continue to evaluate indefinitely as 1 will always evaluate to a non-nil value. The only way to exit such a loop is to force a break in evaluation using ESC.

 

If you wish to exit the program in a standard manner (e.g. using ENTER, SPACE, right-click), then you will need to prompt the user for a point to which the object should be copied (using getpoint), and then test for valid input received before proceeding.

 

For example:

(while (setq pt1 (getpoint "\nSpecify point <exit>: "))
    (command "_.copy" obline "" "_non" Pt2 "_non pt1)
)

You may also want to look into using the COPYMODE system variable, as this will avoid the need for a loop entirely.

Posted

Thanks Lee

I have replaced the first one with the second and it exits with "ESCAPE" or "ENTER"

I don't know why I was making it so hard but using "xline " then "A" Autocad says "Enter angle of xline (0.00) or [Reference]: I didn't think to just pick 2 points here

(defun c:conlob (/ *error* Pt1 Pt2 obline)
  (defun *error* (x)
    (resetoldvar)
    (princ "\n*Cancel*")
    )
  (savevartoold) (constructionlayer)
    (setq Pt1 (getpoint "\nPick First Point:")
          Pt2 (getpoint Pt1 "\nPick Second Point:"))
    (command "_xline" Pt1 Pt2 "")
    (setq obline (entlast))
   (while 1
   (command "_copy" obline "" Pt2 pause (command)))
  (resetoldvar)
 (princ)
)

(defun c:conlobl (/ Pt1 Pt2 obline)
 (savevartoold) (constructionlayer)
  (setq Pt1 (getpoint "\nPick First Point:")
        Pt2 (getpoint Pt1 "\nPick Second Point:"))
   (command "_xline" "A" Pt1 Pt2)
   (while (= (getvar "cmdactive") 1) (vl-cmdf "\\"))
  (resetoldvar)
 (princ)
)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...