Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

confusion about a program

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
265 Views, 3 Replies

confusion about a program

( defun c:test()



( command "line" )



( alert "hello" )

)



In this program alert message is displayed before the line command is executed, what is the reason and how to get



rid from it. If i use ( command "line" (getpoint) (getpoint) "" ) for the first line of code, ORTHO mode does not work



and I want to draw the line using ortho mode.
3 REPLIES 3
Message 2 of 4
arcticad
in reply to: Anonymous

Here is a simple example of drawing a single line
^C is used to cancel line so it won't continue

{code}
(DEFUN line_errortrap (errmsg)
(PRINC errmsg)
(SETQ *error* temperr)
; Reset OrthoMode is ESC
(setvar "Orthomode" orthomode)
; Clean Up Global Variable
(setq orthomode nil)
(PRINC)
)


(defun C:Dline ( / pt1 pt2)
; Set Error check if ESC is pressed
(SETQ temperr *error*)
(SETQ *error* line_errortrap)
(setq OrthoMode (getvar "Orthomode"))
(setvar "Orthomode" 1)
(setq pt1 (getpoint "Select First Point: "))
(setq pt2 (getpoint pt1 "Select Second Point: "))

(command "line" pt1 pt2 ^C)
(setvar "Orthomode" orthomode)
; Clean Up Global Variable
(setq orthomode nil)
(alert "Hello")
(princ)
)
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 4
Kent1Cooper
in reply to: Anonymous

Use pause instead of (getpoint). That will honor running Ortho if it's on, and show the rubber band.

(command "line" pause pause "")

You can force Ortho on first, if you want to be sure it's on, when it may not be:

(setvar 'orthomode 1)
(command "line" pause pause "")

If you want to be able to continue the Line command beyond a single Line segment, and don't want tie down the number of Lines, use that old standby, the check-the-CMDACTIVE-System-Variable thing, to make it keep waiting for User input until the Line command is finished:

{code}
(command "_.line")
(while (> (getvar 'cmdactive) 0)
(command pause)
); end while
(alert "hello")
{code}

--
Kent Cooper


salman_nsr wrote...
....alert message is displayed before the line command is executed, what is the reason and how to get rid from it. If i use ( command "line" (getpoint) (getpoint) "" ) for the first line of code, ORTHO mode does not work
Kent Cooper, AIA
Message 4 of 4
Kent1Cooper
in reply to: Anonymous

If you want to involve error handling, there's now a simpler way to do that. It hasn't always been available, so you'll find lots of examples of the older more complicated way in the Discussion Group history.

For a few versions now, you've been able to define the *error* function as if it were a variable, *inside* a larger function definition, and localize it. That way, it will only apply within that routine, and you don't need to save the current [presumably AutoCAD's native] error handling, and restore it later, or deal with a variable to do all of that with.

The Line command will provide its own prompt, so there's really no need for the point variables and (getpoint) functions.

^C means nothing in Lisp -- it's macro language. It only works here *because* it means nothing, that is, it returns nil, and that happens to end some commands. You would get the same effect by using MarilynMonroe [provided you haven't set a value to that as a variable]. The better way to end a command such as Line or Layer or Chprop is with Enter, or in Lisp terms, "".

This will do exactly the same:

{code}
(defun D:Dline (/ *error*)
(defun *error* (errmsg)
(princ errmsg)
(setvar 'orthomode orthomode)
); end defun - *error*
(setq orthomode (getvar 'orthomode))
(setvar 'orthomode 1)
(command "line" pause pause "")
(setvar 'orthomode orthomode)
(alert "Hello")
(princ)
); end defun - Dline
{code}

--
Kent Cooper
Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report