Improve .lsp

Improve .lsp

adaptacad
Advocate Advocate
983 Views
4 Replies
Message 1 of 5

Improve .lsp

adaptacad
Advocate
Advocate

Hello guys
Some time asking for help to edit this lisp helped me and it was perfect !!!
but I would like to make some changes I will be very grateful if someone helps me;)
1- I would like to see the place before inserting (preview).
2- Store the last inserted text (the first time I insert it it works normally), but when I call the command again it asks me if I want a new one or continue from what I had stopped.
3- And in the rotating option it does something similar to the command.

Thanks for the help !!!

 

(defun c:demo_nom ( / idx ser prf pnt str num)

  (setq ser '(""
              ".1"
              ".1.1" ".1.2" ".1.3" ".1.4"
              ".2"
              ".2.1" ".2.2" ".2.3" ".2.4"
              ".3"
              ".3.1" ".3.2" ".3.3" ".3.4"
              ".4"
              ".4.1" ".4.2" ".4.3" ".4.4"
              )

        idx -1)

  (setq prf (getstring "\nPrefix: "))
  (setq num (cond ((getint "\nInitial number <1>: "))
                  (1)))

  (while (progn
           (if (not (setq str (nth (setq idx (1+ idx)) ser)))
             (setq str (nth (setq idx 0) ser)
                   num (1+ num)))
           (initget "Skip Rotate")
           (setq pnt (getpoint (strcat "\nClick to place No. '" (setq str (strcat prf (if (< num 10) "0" "") (itoa num) str)) "' or [Skip/Rotate]: "))))

    (cond ((= pnt "Skip"))

          ((= pnt "Rotate")
           (initget 1)
           (setq pnt (getpoint (strcat "\nClick to place No. '" str "': ")))
           (command "_Text" "_J" "_MC" "_none" pnt 2.5 PAUSE str))

          (T
           (command "_Text" "_J" "_MC" "_none" pnt 2.5 0 str))))         
  (princ)
  )
0 Likes
Accepted solutions (2)
984 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try the following code. It's not really that simple, especially the preview part. So it requires some compromises - There simply has to be 2 user prompts. Best I could do is that the second one is optional under <enter>. If you want to Exit the routine, you should hit the <enter> twice. 

The Rotate option now works differently - place the text, hit <options>, then you're able to rotate previously placed text. It's like using the TEXT command, then the ROTATE.

 

(defun c:demo_nom ( / *error* cmd ser ptl str opt tmp)
  ;; global vars: *nom-prf* *nom-num* *nom-idx* 
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if cmd (setvar 'CMDECHO cmd))
    (princ))

  ; --------------------------------------------------------------------------------------------------------------------
  
  (setq cmd (getvar 'CMDECHO)
	ser '(""
	      ".1"
	      ".1.1" ".1.2" ".1.3" ".1.4"
	      ".2"
	      ".2.1" ".2.2" ".2.3" ".2.4"
	      ".3"
	      ".3.1" ".3.2" ".3.3" ".3.4"
	      ".4"
	      ".4.1" ".4.2" ".4.3" ".4.4")
	
	*nom-idx* (max (1- (cond (*nom-idx*)
				 (0)))
		       -1))
  
  (or *nom-num*
      (setq *nom-num* 1))
  
  (setq *nom-num* (cond ((setq tmp (getint (strcat "\nInitial number <"
						   (cond (*nom-prf*) (""))
						   (if (< *nom-num* 10) "0" "")
						   (itoa *nom-num*)
						   (nth (1+ *nom-idx*) ser)
						   ">: ")))
			 (setq *nom-idx* -1
			       *nom-prf* nil)
			 tmp)
			(*nom-num*)))
  
  (if (not *nom-prf*)
    (setq *nom-prf* (getstring "\nPrefix: ")))
  
  (while (progn
	   (if (not (setq str (nth (setq *nom-idx* (1+ *nom-idx*)) ser)))
	     (setq str (nth (setq *nom-idx* 0) ser)
		   *nom-num* (1+ *nom-num*)))
	   (setq str (strcat *nom-prf*
			     (if (< *nom-num* 10) "0" "")
			     (itoa *nom-num*)
			     str))
	   (or ptl
	       (setq ptl '(0 0 0)))
	   
	   (setq enl (entlast))
	   (princ (strcat "\nClick to place No. '" str  "' or <options>: "))
	   (setvar 'CMDECHO 0)
	   (command "_.TEXT" "_none" ptl "" 0 str
		    "_.MOVE" "_Last" "" "_none" ptl PAUSE)
	   (setvar 'CMDECHO 1)
	   
	   (if (equal ptl (getvar 'LASTPOINT))
	     (progn
	       (initget "Skip Rotate")
	       (setq opt (getkword (strcat "\nSelect from options [Skip/Rotate] <exit>: ")))

	       (cond ((= opt "Skip")
		      (if (not (equal enl (entlast)))
			(entdel (entlast))))
		     
		     ((= opt "Rotate")
		      (if (not (equal enl (entlast)))
			(entdel (entlast)))
		      (setq *nom-idx* (1- *nom-idx*))
		      (command-s "_.Rotate" enl "" "_none" ptl))
		     
		     (T
		      nil))) 				; Nil by <exit> for (while)
	     (setq ptl (getvar 'LASTPOINT))))) 		; True for (while)
  (*error* "end")
  )

 

0 Likes
Message 3 of 5

adaptacad
Advocate
Advocate

Perfect perfect perfect ... @ВeekeeCZ


I will mark as solution because it will help me a lot, thank you !!

But there is a detail, when I turn on the rotate, it leaves, the command, it could not leave and it continues XX03->  XX03.1-> XX03.1.1.

 

If you can not, it's okay, once again.
Thank you very much, you are perfect.

0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Yeap, it was really a detail. The routine keeps on running after the Rotate.

 

(defun c:demo_nom ( / *error* cmd ser ptl str opt tmp)
  ;; global vars: *nom-prf* *nom-num* *nom-idx* 
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if cmd (setvar 'CMDECHO cmd))
    (princ))

  ; --------------------------------------------------------------------------------------------------------------------
  
  (setq cmd (getvar 'CMDECHO)
	ser '(""
	      ".1"
	      ".1.1" ".1.2" ".1.3" ".1.4"
	      ".2"
	      ".2.1" ".2.2" ".2.3" ".2.4"
	      ".3"
	      ".3.1" ".3.2" ".3.3" ".3.4"
	      ".4"
	      ".4.1" ".4.2" ".4.3" ".4.4")
	
	*nom-idx* (max (1- (cond (*nom-idx*)
				 (0)))
		       -1))
  
  (or *nom-num*
      (setq *nom-num* 1))
  
  (setq *nom-num* (cond ((setq tmp (getint (strcat "\nInitial number <"
						   (cond (*nom-prf*) (""))
						   (if (< *nom-num* 10) "0" "")
						   (itoa *nom-num*)
						   (nth (1+ *nom-idx*) ser)
						   ">: ")))
			 (setq *nom-idx* -1
			       *nom-prf* nil)
			 tmp)
			(*nom-num*)))
  
  (if (not *nom-prf*)
    (setq *nom-prf* (getstring "\nPrefix: ")))
  
  (while (progn
	   (if (not (setq str (nth (setq *nom-idx* (1+ *nom-idx*)) ser)))
	     (setq str (nth (setq *nom-idx* 0) ser)
		   *nom-num* (1+ *nom-num*)))
	   (setq str (strcat *nom-prf*
			     (if (< *nom-num* 10) "0" "")
			     (itoa *nom-num*)
			     str))
	   (or ptl
	       (setq ptl '(0 0 0)))
	   
	   (setq enl (entlast))
	   (princ (strcat "\nClick to place No. '" str  "' or <options>: "))
	   (setvar 'CMDECHO 0)
	   (command "_.TEXT" "_none" ptl "" 0 str
		    "_.MOVE" "_Last" "" "_none" ptl PAUSE)
	   (setvar 'CMDECHO 1)
	   
	   (if (equal ptl (getvar 'LASTPOINT)) ; = <options> chosen
	     (progn
	       (initget "Skip Rotate")
	       (setq opt (getkword (strcat "\nSelect from options [Skip/Rotate] <exit>: ")))

	       (cond ((= opt "Skip")
		      (if (not (equal enl (entlast)))
			(entdel (entlast))))
		     
		     ((= opt "Rotate")
		      (if (not (equal enl (entlast)))
			(entdel (entlast)))
		      (setq *nom-idx* (1- *nom-idx*))
		      (command-s "_.Rotate" enl "" "_none" ptl)))
               
               opt)						; Nil by <exit> for (while), otherwise T
             (setq ptl (getvar 'LASTPOINT))))) 			; True for (while)
  (*error* "end")
  )
0 Likes
Message 5 of 5

adaptacad
Advocate
Advocate

 

Thank you !!!!!! Heart