Nested Command Error with Autolisp
Nested Command Error with Autolisp
(OP)
Hello,
I've written an Autolisp routine which uses the "command" function. It works perfectly three times, with no errors and gets back to the command prompt. The fourth time I use the command I get an error: "Fatal Error, Commands may not be nested more than four deep".
I have looked to make sure all the commands are finished and close properly.
I would like to find what is causing this error, or failing that, to find a way to clear some command buffer or other work-around. Using (command) doesn't work.
I'm using AutoCAD 2006 on XP Pro.
TIA,
MJ
I've written an Autolisp routine which uses the "command" function. It works perfectly three times, with no errors and gets back to the command prompt. The fourth time I use the command I get an error: "Fatal Error, Commands may not be nested more than four deep".
I have looked to make sure all the commands are finished and close properly.
I would like to find what is causing this error, or failing that, to find a way to clear some command buffer or other work-around. Using (command) doesn't work.
I'm using AutoCAD 2006 on XP Pro.
TIA,
MJ





RE: Nested Command Error with Autolisp
RE: Nested Command Error with Autolisp
;No att editing here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;bki.lsp - MAJ - 8-7-10
;Type "bki" (without the quotes) on the command line
; ------ MAIN FUNCTION ---------------
;Main Function
(defun c:bki ( / resp resp2 ss counter edata data1 data2 frac1 frac2
ename oldcmdecho oldclayer oldcecolor oldosmode oldsnapmode oldorthomode
oldhpang oldhpname oldhpscale oldpickbox)
(princ "\n bki\n")
(if (not bkiblock) (setq bkiblockname (getstring "\n What is Block Name? ... ")))
(setq bkiblock (strcat "*" bkiblockname))
(getvarlist) ;initializes
(setvar "osmode" 0)
(princ "\n Pick LINES ")
(setq ename (car (entsel "\n Pick a LINE")))
(setq edata (entget ename))
(setq data1 (assoc '10 edata))
(setq p1 (cdr data1))
(setq data2 (assoc '11 edata))
(setq p2 (cdr data2))
(setq len (sqrt (+ (* (- (car p2)(car p1))(- (car p2)(car p1)))
(* (- (cadr p2)(cadr p1))(- (cadr p2)(cadr p1)))
(* (- (caddr p2)(caddr p1))(- (caddr p2)(caddr p1)))
)
)
) ;setq len
(setq p4 (list (car p1)(cadr p1)(+ (caddr p1) len)));len out
;;;;;;;;; points are calculated - begin operations ;;;;;;
(command "insert" bkiblock p1 "" "")
(command "align" "l" "" p1 p1 p4 p2 "" "")
(command "extrude" "l" "" len "")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setvarlist) ;restores environment
);end of main function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The following two routines store and restore the current environment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun getvarlist () ;subroutine to record environment
(setq
oldcmdecho (getvar "cmdecho")
oldclayer (getvar "clayer")
oldcecolor (getvar "cecolor")
oldosmode (getvar "osmode")
oldsnapmode (getvar "snapmode")
oldorthomode (getvar "orthomode")
oldhpang (getvar "hpang")
oldhpname (getvar "hpname")
oldhpscale (getvar "hpscale")
oldpickbox (getvar "pickbox")
oldedgemode (getvar "edgemode")
)
(princ)
)
(defun setvarlist () ;subroutine to restore environment
(setvar "cmdecho" oldcmdecho)
(setvar "clayer" oldclayer)
(setvar "cecolor" oldcecolor)
(setvar "osmode" oldosmode)
(setvar "snapmode" oldsnapmode)
(setvar "orthomode" oldorthomode)
(setvar "hpang" oldhpang)
(setvar "hpname" oldhpname)
(setvar "hpscale" oldhpscale)
(setvar "pickbox" oldpickbox)
(setvar "edgemode" oldedgemode)
(princ)
)
(princ "\n bki.lsp loaded ")(princ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TIA
;MJ
RE: Nested Command Error with Autolisp
I wonder if 'len' might be an alias for LENGTHEN. Since the variable 'len' is not declared local, that may be confusing the system.
RE: Nested Command Error with Autolisp
(align (lastent) p1 p2 p3 p4)
First you have to load it as follows
(command "align") (command)
That seems to make it work all the time.
MJ