Use of TAB "What is the error of this code"

Use of TAB "What is the error of this code"

Anonymous
Not applicable
880 Views
2 Replies
Message 1 of 3

Use of TAB "What is the error of this code"

Anonymous
Not applicable

Hello everyone,
I'm trying to make a program to insert 8 blocks, but I'm finding some logical error.
My goal is to insert blocks, however, I would like to switch between them using the TAB key, but the program simply does not work.
If anyone can help me I would be very grateful.

 

(defun c:UserTAB (/ blocklist loop)
  (setq	blocklist(list "Block01" "Block02" "Block03" "Block04" "Block05" "Block06" "Block07" "Block08")
	loop t)
  
  (setvar "CMDECHO" 0)
  (progn
    (princ"\n[TAB / Enter / Esc <Exit>]")
    (princ (strcat "\nInsert <"(car blocklist)">: "))
    (while loop
      (setq inp (vl-catch-all-apply 'grread (list nil 8 0)))
      (if (vl-catch-all-error-p inp)
	(progn (princ "Function Canceled!")
	  (setq loop nil)
	  )
	(progn
	  (cond
	    ((or (equal inp '(2 9)) (= (car inp) 3))
	     (setq blocklist (append (cdr blocklist) (list (car blocklist))))
	     (princ (strcat "\nInsert <"(car blocklist)">: "))
	     )
	    ((or (equal inp '(2 13))
		 (equal inp '(2 32))
		 (= (car inp) 25)
		 )
	     (if (findfile (strcat "C:\\Blocks\\" blocklist ".dwg" "_Scale" 1 pause "" "_.Explode" (entlast)))
	       (vl-cmdf "_.Insert" (strcat blocklist) "_Scale" 1 pause "" "_.Explode" (entlast))
	       )
	     (setq loop nil)
	     )
	    ((member inp '((2 88) (2 120))) (setq loop nil))
	    );Cond
	  );Progn
	);Case
      );While
    );Progn
  (setvar "CMDECHO" 1)
  (princ)
  )
(vl-load-com)
0 Likes
Accepted solutions (1)
881 Views
2 Replies
Replies (2)
Message 2 of 3

doaiena
Collaborator
Collaborator
Accepted solution

I think this is what you are going after:

(defun c:UserTAB (/ blocklist loop inp pt)
  (setq	blocklist (list "Block01" "Block02" "Block03" "Block04" "Block05" "Block06" "Block07" "Block08")
	loop	  t
  )

  (setvar "CMDECHO" 0)
  (progn
    (princ "\n[TAB / Enter / Esc <Exit>]")
    (princ (strcat "\nInsert <" (car blocklist) ">: "))
    (while loop
      (setq inp (vl-catch-all-apply 'grread (list nil 8 0)))
      (if (vl-catch-all-error-p inp)
	(progn (princ "Function Canceled!")
	       (setq loop nil)
	)
	(progn
	  (cond
	    ((or (equal inp '(2 9)) (= (car inp) 3))
	     (setq blocklist (append (cdr blocklist) (list (car blocklist))))
	     (princ (strcat "\nInsert <" (car blocklist) ">: "))
	    )
	    ((or (equal inp '(2 13))
		 (equal inp '(2 32))
		 (= (car inp) 25)
	     )
	     (if (findfile (strcat "C:\\Blocks\\" (car blocklist) ".dwg"))
	       (progn
		 (setq pt (getpoint "\nPick insertion point: "))
		 (vl-cmdf "_Insert" (strcat "C:\\Blocks\\" (car blocklist) ".dwg") "_X" 1.0 "_Y" 1.0 "_Z" 1.0 pt 0)
		 (vl-cmdf "_explode" (entlast))
	       )
	     )
	     (setq loop nil)
	    )
	    ((member inp '((2 88) (2 120))) (setq loop nil))
	  ) ;Cond
	) ;Progn
      ) ;Case
    ) ;While
  ) ;Progn
  (setvar "CMDECHO" 1)
  (princ)
)
(vl-load-com)
Message 3 of 3

Anonymous
Not applicable

Very very good @
Changing these lines I get the result I hope !!

(if (findfile (strcat "C:\\Blocks\\" (car blocklist) ".dwg"))
	       (vl-cmdf "_Insert" (strcat "C:\\Blocks\\" (car blocklist) ".dwg") "_X" 1.0 "_Y" 1.0 "_Z" 1.0 pause "")
	       (vl-cmdf "_explode" (entlast))
	     )

Thank you !! Robot Mad