Jump to content

How to I get this modify text size to work?


AeJay

Recommended Posts

I have been lost as to where to place the code ";(list (cons 40 textSize)) ; add text size to modified text entity" to modify the texts to that it will be replacing.

 

(defun c:MTP (/ cEnt elst text color ss i textSize)
	(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
				(member (cdr (assoc 0 (entget cEnt)))
					'("TEXT" "MTEXT" "ATTRIB")
				)
		1)
		(progn
		(setq elst (entget cEnt)
			  text (assoc 1 elst)
			  color (cond ((assoc 62 elst))
						(T '(62 . 256))
					)
			  textSize (cdr (assoc 40 elst)) ; get text size
		)
		(redraw cEnt 3)
				(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
				(repeat (setq i (sslength ss))
				(setq elst (entget (ssname ss (setq i (1- i)))))
					(entmod
						(subst text
							(assoc 1 elst)
								(if (assoc 62 elst)
								(entmod (subst color (assoc 62 elst) elst))
								(append elst (list color))
								;(list (cons 40 textSize)) ; add text size to modified text entity
							)						
						)
						;(list (cons 40 textSize)) ; add text size to modified text entity
					)
				)
			)
	    )
	)
	(command "_regenall")
	(princ)
)

 

Link to comment
Share on other sites

I tried my new code below but I get an error of "Program ERROR: bad DXF group: 50.0". Please help.

(defun c:MTP (/ cEnt elst text color ss i textSize)
	(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
				(member (cdr (assoc 0 (entget cEnt)))
					'("TEXT" "MTEXT" "ATTRIB")
				)
		1)
		(progn
		(setq elst (entget cEnt)
			  text (assoc 1 elst)
			  color (cond ((assoc 62 elst))
						(T '(62 . 256))
					)
			  textSize (cdr (assoc 40 elst)) ; get text size
		)
		(redraw cEnt 3)
				(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
				(repeat (setq i (sslength ss))
				(setq elst (entget (ssname ss (setq i (1- i)))))
					(entmod
						(subst text
							(assoc 1 elst)
								(if (assoc 62 elst)
								(entmod (subst color (assoc 62 elst) elst))
								(append elst (list color))
							)
							(entmod (subst textSize (assoc 40 elst) elst))
							(append elst (list textSize))
						)					
					)
				)
			)
	    )
	)
	(command "_regenall")
	(princ)
)

 

Link to comment
Share on other sites

8 hours ago, AeJay said:

"Program ERROR: bad DXF group: 50.0"

@AeJay

 

The error comes from this line 

 

(entmod (subst textSize (assoc 40 elst) elst))

 

Not know how to fix 

 

 

 

Edited by devitg
Link to comment
Share on other sites

1 hour ago, devitg said:
9 hours ago, AeJay said:

"Program ERROR: bad DXF group: 50.0"

@AeJay

 

The error comes from this line 

 

(entmod (subst textSize (assoc 40 elst) elst))

 

Not know how to fix 

 

If you look earlier in the code:

"textSize (cdr (assoc 40 elst))" returns only the value and not the association list.

 

You have to plug the value back in as an equivalent dotted pair, so change:

"(entmod (subst textSize (assoc 40 elst) elst))" to "(entmod (subst (cons 40 textSize) (assoc 40 elst) elst))"

 

ALTERNATELY, you can just change:

"textSize (cdr (assoc 40 elst))" to "textSize (assoc 40 elst)"

Edited by pkenewell
  • Like 1
Link to comment
Share on other sites

7 hours ago, pkenewell said:

 

If you look earlier in the code:

"textSize (cdr (assoc 40 elst))" returns only the value and not the association list.

 

You have to plug the value back in as an equivalent dotted pair, so change:

"(entmod (subst textSize (assoc 40 elst) elst))" to "(entmod (subst (cons 40 textSize) (assoc 40 elst) elst))"

 

ALTERNATELY, you can just change:

"textSize (cdr (assoc 40 elst))" to "textSize (assoc 40 elst)"

I tried the alternative method, the error now is "too many arguments" but the interesting thing is it does copy the source text's text height but doesn't copy the source text's text and color anymore.

Link to comment
Share on other sites

14 hours ago, AeJay said:

I tried the alternative method, the error now is "too many arguments" but the interesting thing is it does copy the source text's text height but doesn't copy the source text's text and color anymore.

 

I found several problems and confusion with your code so I just rewrote it. Give this a try (minimally tested):

NOTES: I changed variable names for 1) don't make variable names the same as an existing command, and 2) keep them shorter; they take up less memory.

(defun c:MTP (/ cEnt elst txt clr ss i txtsz)
   (if (and 
         (setq cEnt (car (nentsel "\nSelect Source Text: ")))
         (member (cdr (assoc 0 (entget cEnt))) '("TEXT" "MTEXT" "ATTRIB"))
       )
      (progn
         (setq elst  (entget cEnt)
               txt   (assoc 1 elst) ; Get Text content
               clr   (cond ((assoc 62 elst))(T '(62 . 256))); Get ACI color
               txtsz (assoc 40 elst) ; get text size
   	     )
         (redraw cEnt 3)
         (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
            (repeat (setq i (sslength ss))
               (setq elst (entget (ssname ss (setq i (1- i)))) ;Get Entity List
                     elst (subst txt (assoc 1 elst) elst) ;Substitute test content in elist
                     elst (if (assoc 62 elst) (subst clr (assoc 62 elst) elst)(append elst (list clr))) ;Substitute ACI color in elist
                     elst (if (assoc 40 elst) (subst txtsz (assoc 40 elst) elst)(append elst (list txtsz))) ;substitute Text Height in elist
               )
               (entmod elst) ; Modify new list
            )
         )
      )
   )
   (command "_regenall")
   (princ)
)

 

Edited by pkenewell
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

11 minutes ago, pkenewell said:

2) keep them shorter; they take up less memory.

@pkenewell

 

Who can worry at this times to save memory, in detriment to misunderstood what the variable mean  ?

 

 

Link to comment
Share on other sites

Just now, devitg said:

Who can worry at this times to save memory, in detriment to misunderstood what the variable mean  ?

@devitg OK well just my preference then. I would rather keep the code shorter and the comments longer. I'm old school that way 😎. When I started coding it made a bigger difference when there was much less memory available.

Link to comment
Share on other sites

5 minutes ago, pkenewell said:

@devitg OK well just my preference then. I would rather keep the code shorter and the comments longer. I'm old school that way 😎. When I started coding it made a bigger difference when there was much less memory available.

@pkenewell for sure , my first ACAD was 2.16   on a AT , circa 1991 .  amber screen .

 

 

  • Like 1
Link to comment
Share on other sites

1 minute ago, devitg said:

for sure , my first ACAD was 2.16   on a AT , circa 1991 .  amber screen .

LOL - not far behind you. R11 for DOS. Circa 1992-93

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...