change text height

change text height

Ranjit_Singh
Advisor Advisor
1,180 Views
16 Replies
Message 1 of 17

change text height

Ranjit_Singh
Advisor
Advisor

I wrote this simple LISP to change text height to 0.1 everywhere in the drawing. VLIDE does not give me any error. But when I run it just sits there. Seems like there is an endless loop. What am I doing wrong.


Thanks.

 

(defun c:chtxt(/ ss i a b)
(setq ss (ssget "_x" '((0 . "*text*"))))
(setq a (ssname ss i))
(setq i 0)
(while (/= a NIL)
(setq b (entget a))
(setq b (subst '(40 0.1) (assoc 40 b) b))
(entmod b)
(1+ i)
(setq a (ssname ss i))
)
(princ)
)
0 Likes
1,181 Views
16 Replies
Replies (16)
Message 2 of 17

Satoews
Advocate
Advocate
(defun c:chtxt(/ ss i a b)
(setq ss (ssget "_x" '((0 . "*text*"))))
(setq a (ssname ss i))
(setq i 0)
(while (/= a NIL)
(setq b (entget a))
(entmod (subst (40 0.1) (assoc 40 b) b))
(1+ i)
(setq a (ssname ss i))
)
(princ)
)

try this

 

edit: screwed up the lisp

Shawn T
0 Likes
Message 3 of 17

Ranjit_Singh
Advisor
Advisor

I see u combined the entmod and setq b statements, which is a good thing, but now I get this error

; error: bad argument type: numberp: nil

 

Not sure how to fix it. I think it has something to do with the loop, but not sure what exactly. Is this statement valid?

(while (/= a NIL)

I tried using

(while (a)

but it still gives me the same error

; error: bad argument type: numberp: nil

0 Likes
Message 4 of 17

ВeekeeCZ
Consultant
Consultant

Then try this...

 

Spoiler
(defun c:chtxt (/ ss i d)
  
  (if (setq ss (ssget "_x" '((0 . "*text"))))

    (repeat (setq i (sslength ss))
      (setq b (entget (ssname ss (setq i (1- i)))))
      (entmod (subst '(40 . 0.1)
		     (assoc 40 b)
		     b))))
  
  (princ)
)

 

and some notes for ya...

Spoiler
(defun c:chtxt(/ ss i a b)
(setq ss (ssget "_x" '((0 . "*text*")))) ; second * not necessary
(setq a (ssname ss i))  ; still did not set i!
(setq i 0)		; move before the line above 
(while (/= a NIL)       ; it's equal to: (while a  
(setq b (entget a))	
(setq b (subst '(40 0.1) (assoc 40 b) b)) ; needs to be '(40 . 0.1)
(entmod b)
(1+ i)			; you need to store it into i variable
(setq a (ssname ss i))
)
(princ)
)

 

Message 5 of 17

hmsilva
Mentor
Mentor

Your code revised

(defun c:chtxt (/ ss i a b)
    (if (setq ss (ssget "_x" '((0 . "*text*"))))
        (progn
            (setq i 0
                  a (ssname ss i)
            )
            (while (/= a nil)
                (setq b (entget a))
                (setq b (subst (cons 40 0.1) (assoc 40 b) b))
                (entmod b)
                (setq i (1+ i)
                      a (ssname ss i)
                )
            )
        )
    )
    (princ)
)

 

or, perhaps something like this

 

(defun c:demo (/ ent i ss)
    (if (setq ss (ssget "_x" '((0 . "*TEXT"))))
        (repeat (setq i (sslength ss))
            (setq ent (entget (ssname ss (setq i (1- i)))))
            (entmod (subst (cons 40 0.1) (assoc 40 ent) ent))
        )
    )
    (princ)
)

 

Hope this helps,
Henrique 

EESignature

Message 6 of 17

Satoews
Advocate
Advocate

It amazes me how fast you guys can do that. 😃 

 

Shawn T
0 Likes
Message 7 of 17

hmsilva
Mentor
Mentor

@Tornac wrote:

It amazes me how fast you guys can do that. 😃 

 


I was too slow....

@ВeekeeCZ beat me to it... 🙂

 

Henrique

EESignature

0 Likes
Message 8 of 17

Ranjit_Singh
Advisor
Advisor

Great job and thanks for the help. I am still unsure why a simple while is giving me a nil error? Can someone explain please. Thanks.

0 Likes
Message 9 of 17

Satoews
Advocate
Advocate

because you set your i before a 

 

(setq a (ssname ss i))  ; still did not set i!
(setq i 0)

and you didn't set your i in the while loop. 

 

 (setq i (1+ i)

i think your lisp just kept running in loops.

Shawn T
0 Likes
Message 10 of 17

Ranjit_Singh
Advisor
Advisor

Thanks! silly me. rookie mistake

0 Likes
Message 11 of 17

Satoews
Advocate
Advocate

Keep at it! Maybe we can both be writing code like bee and hmsilva eventually 😃 When you have the time go over both hmsilvas and bee's code and look what they did to 1. fix your code and 2. optimize your code. and 3. how their codes differ from one another.

Shawn T
0 Likes
Message 12 of 17

ВeekeeCZ
Consultant
Consultant

@hmsilva wrote:

@Tornac wrote:

It amazes me how fast you guys can do that. 😃 

 


I was too slow....

@ВeekeeCZ beat me to it... 🙂

 

Henrique


🙂 This time.

 

But it's not a rase! I would rather be if there was a button... something like "I am on it!"

0 Likes
Message 13 of 17

hmsilva
Mentor
Mentor

@ВeekeeCZ wrote:

@hmsilva wrote:

@Tornac wrote:

It amazes me how fast you guys can do that. 😃 

 


I was too slow....

@ВeekeeCZ beat me to it... 🙂

 

Henrique


🙂 This time.

 

But it's not a rase! I would rather be if there was a button... something like "I am on it!"


Of course it is not a race, the 'beat me' was just because your answer was posted a few seconds before mine, and if I had seen your answer, I wouldn't post mine, your answer was correct...

 

Cheers

Henrique

EESignature

0 Likes
Message 14 of 17

Ranjit_Singh
Advisor
Advisor

Right! I will get there in a couple years (or decades maybe Smiley Wink) Here is my revised code with all improvements from everyones input. Thankyou all.

(defun c:chtxht(/ i a)
(setq i -1)
(while (setq a (ssname (ssget "_x" '((0 . "*text*"))) (setq i (1+ i))))
	(entmod (subst (cons 40 0.1) (assoc 40 (entget a)) (entget a)))
)
(princ)
)
0 Likes
Message 15 of 17

dbroad
Mentor
Mentor

Remember also

1) You don't need a program to do this.  CTRL+A selects everything.  In properties palette choose text.  Enter the text height.

2) These kinds of programs will not change the embedded text heights in mtext (where words/characters have size modifiers).

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 16 of 17

ВeekeeCZ
Consultant
Consultant

@Ranjit_Singh wrote:

Right! I will get there in a couple years (or decades maybe Smiley Wink) Here is my revised code with all improvements from everyones input. Thankyou all.

(defun c:chtxht(/ i a)
(setq i -1)
(while (setq a (ssname (ssget "_x" '((0 . "*text*"))) (setq i (1+ i))))
	(entmod (subst (cons 40 0.1) (assoc 40 (entget a)) (entget a)))
)
(princ)
)

- don't make a selection each time while it tests the condition!!! It could be different!!
- generally, in this kind of cases where you need to go throw the WHOLE selection set, it's better repeat function. You tell the repeat function how many cycles you need and no other test is required. In opposite to the while function, where is tested each run.

 

(defun c:chtxt (/ i a ss)
  (setq i -1
	ss (ssget "_x" '((0 . "*text*"))))
  (while (setq a (ssname ss (setq i (1+ i))))
    (entmod (subst (cons 40 0.1) (assoc 40 (entget a)) (entget a))))
  (princ)
)
0 Likes
Message 17 of 17

ВeekeeCZ
Consultant
Consultant

@hmsilva wrote:

@ВeekeeCZ wrote:

@hmsilva wrote:

@Tornac wrote:

It amazes me how fast you guys can do that. 😃 

 


I was too slow....

@ВeekeeCZ beat me to it... 🙂

 

Henrique


🙂 This time.

 

But it's not a rase! I would rather be if there was a button... something like "I am on it!"


Of course it is not a race, the 'beat me' was just because your answer was posted a few seconds before mine, and if I had seen your answer, I wouldn't post mine, your answer was correct...

 

Cheers

Henrique


Of course!!! I know how this works. 🙂 cheers

0 Likes