Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Command Error with Autolisp

Status
Not open for further replies.

MarkAJohn

Structural
Nov 28, 2001
36
0
0
US
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
 
Replies continue below

Recommended for you

That problem seems to happen most with attribute editing, judging by postings. May be a problem with command not terminating but sounds like you've tried that. Can you post code that seems to be the problem?
 
Here is the code:
;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
 
MarkAJohn,
I wonder if 'len' might be an alias for LENGTHEN. Since the variable 'len' is not declared local, that may be confusing the system.
 
I found the answer on an Autodesk forum. The ALIGN command is an external command and can't be called with the command function. You have to call it as follows:
(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
 
Status
Not open for further replies.
Back
Top