×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Nested Command Error with Autolisp

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  

RE: Nested Command Error with Autolisp

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?

RE: Nested Command Error with Autolisp

(OP)
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

RE: Nested Command Error with Autolisp

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.

RE: Nested Command Error with Autolisp

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources