Jump to content

Text and Grread


amcdicsac

Recommended Posts

Hi.

 

I have this code that inserts a text using grread function to which I want to add the option to rotate and resize but I have no idea how to do it would appreciate the help.

 

Thanks

 

(defun c:xaa (/ potencia prefijo pt)
(setvar "cmdecho" 0)
(setq potencia (strcase (getstring T "\nIngresa potencia monofásica: ")))
(setq prefijo (*AX_mtext* (strcat potencia "\\P" "1Ø/220V")))
(while
 (eq (car (setq pt (grread t 15 0))) 5) 
 (redraw)
(entmod (subst (cons 10 (cadr pt)) (assoc 10 (entget prefijo)) (entget prefijo))))
(setvar "cmdecho" 1)
(princ))

(defun *AX_mtext* (s)
  (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")         
           (cons 100 "AcDbMText")   
           (list 10 0. 0. 0.)
           (list 11 0. 0. 0.)
           (cons 71 1) 
           (cons 40 0.2) 
           (cons  1 s)
       (cons  7 "0-DEU-ROMANS")

     )
  )
)

Link to comment
Share on other sites

Okay, the height increment is set to 0.1 units:

(defun C:test ( / potencia prefijo msg enx n sizeInc cmd grr )
(if 
	(and
		(setq potencia (strcase (getstring T "\nIngresa potencia monofásica: ")))
		(setq prefijo (*AX_mtext* (strcat potencia "\\P" "1Ø/220V")))
		(setq msg "\nPress [+/-] to increase/decrease the size, [TAB] to rotate <exit>: ")
		(setq enx (entget prefijo))
		(setq n (cdr (assoc 40 enx)))
		(setq sizeInc 0.1)
	); and
	(progn
		(setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
		(and msg (princ msg)) (setvar 'errno 0)
		(while (/= 52 (getvar 'errno))
			(setq grr (grread T))
			(cond
				((= (car grr) 2) 
					(and msg (princ msg)) 
					(and (= (chr (cadr grr)) "\r") (setvar 'errno 52))
					(cond 
						((= (chr (cadr grr)) "+")
							(setq n (+ n sizeInc))
							(entmod (setq enx (subst (cons 40 n) (assoc 40 enx) enx)))
						)
						((= (chr (cadr grr)) "-")
							(setq n (- n sizeInc))
							(or (not (minusp n)) (setq n 0.1))
							(entmod (setq enx (subst (cons 40 n) (assoc 40 enx) enx)))
						)
						((= (cadr grr) (ascii (strcase "\t" T)))
							(entmod (setq enx (subst (cons 50 (+ (cdr (assoc 50 enx)) (/ PI 2.))) (assoc 50 enx) enx)))
						)
					); cond
				)
				( (= (car grr) 25) (setvar 'errno 52) )
				( (= (car grr) 5) (and msg (princ msg)) (entmod (subst (cons 10 (cadr grr)) (assoc 10 (entget prefijo)) (entget prefijo))) )
				( (= (car grr) 3) (setvar 'errno 52) )
			); cond			
		); while
		(and cmd (setvar 'cmdecho cmd))
	); progn
); if
(princ)
); defun C:test

(defun *AX_mtext* (s)
(entmakex
	(list 
		(cons 0 "MTEXT")         
		(cons 100 "AcDbEntity")         
		(cons 100 "AcDbMText")   
		(list 10 0. 0. 0.)
		(list 11 0. 0. 0.)
		(cons 71 1) 
		(cons 40 0.2) 
		(cons 1 s)
		(cons 7 "0-DEU-ROMANS")
	)
)
)

Link to comment
Share on other sites

@Grrr:

Your use of the errno variable is very peculiar. The errno variable when set by the CAD program has a very specific meaning. I am not saying that what you are doing is wrong, but using your own (boolean) variable instead would make more sense.

 

@Roy, the whole thing started when I was learning about "pseudo loops", mostly from Lee Mac's codes.

Figured out that it has such potential, instead of localizing a new variable with setq function, overall I'm trying to reduce the amount of setq's.

Thanks for posting this, it will shed more light.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...