Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing Text Color & width Factor With Lisp

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
sovby
15399 Views, 15 Replies

Changing Text Color & width Factor With Lisp

What is the best way to change the color of two pieces of specific text in lisp? I want to change where it says (strcase ln6) & (strcase ln7) to the color of green. I tried it a couple of different ways but I'm having some trouble. First I am setting the current layer with a color of blue. I am then running the text command a couple of times. I want to run the mtext command a couple of times but I want the text to be green & I want the width factor to be .85

15 REPLIES 15
Message 2 of 16
Ajilal.Vijayan
in reply to: sovby

Try with the command CHPROP in between the text command

 

(COMMAND "CHPROP" "L" "" "C" 3 "")

 

Your program will look like this.

 ((= (strcase (GETVAR "PROJECTNAME")) "IAT3")(COMMAND "-LAYER" "M" "A-ANNO-TTLB" "C" "5" "" "")
 (COMMAND "TEXT" "S" "ISOCP" "J" "MC" "34.0834,1.7917" ".1875" "" DATE "") 
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "TEXT" "S" "ISOCP" "J" "MC" "33.5938,1.0833" ".1875" "" ln3 "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "-MTEXT" "33.1667,6.1350" "S" "Style-font096" "H" ".1042" "J" "TL" "W" "" (STRCASE ln6) (STRCASE ln7) "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "-MTEXT" "34.6054,6.2917" "S" "Style-font096" "H" ".1042" "J" "TL" "W" "" ln10 "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 )

 

Message 3 of 16
Ajilal.Vijayan
in reply to: sovby


@sovby wrote:

to run the mtext command a couple of times but I want the text to be green & I want the width factor to be .85


Also try with the below line for TEXT

 

add the below codes after the TEXT command

(setq Txt (entget (entlast)));Get last object
(if (assoc 62 Txt);if not bylayer
(setq Txt (subst (cons 62 3)(assoc 62 Txt)Txt));for text (not bylayer)color --> Green
(setq Txt (append (list (cons 62 3))Txt));for text(bylayer) color --> Green
);if
(setq Txt (subst (cons 41 0.85)(assoc 41 Txt)Txt));for text width --> 0.85
(entmod Txt);Modify the text

 

Message 4 of 16
sovby
in reply to: Ajilal.Vijayan

Thanks

Message 5 of 16
Kent1Cooper
in reply to: sovby


@sovby wrote:

What is the best way to change the color of two pieces of specific text in lisp? ....


Another approach would be to save the value of the CECOLOR System Variable, set it to 3, draw whatever you want to be green, and set CECOLOR back to what it was before.

Kent Cooper, AIA
Message 6 of 16
stanovb
in reply to: Ajilal.Vijayan


@Ajilal.Vijayan wrote:

Try with the command CHPROP in between the text command

 

(COMMAND "CHPROP" "L" "" "C" 3 "")

 

Your program will look like this.

 ((= (strcase (GETVAR "PROJECTNAME")) "IAT3")(COMMAND "-LAYER" "M" "A-ANNO-TTLB" "C" "5" "" "")
 (COMMAND "TEXT" "S" "ISOCP" "J" "MC" "34.0834,1.7917" ".1875" "" DATE "") 
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "TEXT" "S" "ISOCP" "J" "MC" "33.5938,1.0833" ".1875" "" ln3 "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "-MTEXT" "33.1667,6.1350" "S" "Style-font096" "H" ".1042" "J" "TL" "W" "" (STRCASE ln6) (STRCASE ln7) "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 (COMMAND "-MTEXT" "34.6054,6.2917" "S" "Style-font096" "H" ".1042" "J" "TL" "W" "" ln10 "")
(COMMAND "CHPROP" "L" "" "C" 3 "")
 )

 


Thanks, This worked. I am not sure what the "ISOP" is for but i used the chprop command like you said. The other solution looks a little more complicated so i went with this one. Thanks to you both but with my limited knowledge of lisp at this point the simpler the better

Message 7 of 16
Kent1Cooper
in reply to: sovby


@sovby wrote:

.... I want to run the mtext command a couple of times but ... I want the width factor to be .85


Unless it's changed in newer versions than what I have here, you can apply a width factor to Text entities, but not to Mtext entities as an override of their Style's width factor.  For Text, here's another way to do so after drawing it:

 

(vla-put-ScaleFactor (vlax-ename->vla-object (entlast)) 0.85)

 

But for either Text or Mtext, you could define a Text Style with a width factor of 0.85 built in, and set that current before drawing the Text/Mtext, or don't set that current but change the Style after the fact using (subst)/(entmod) or (vla-put...) methods.

Kent Cooper, AIA
Message 8 of 16
Ajilal.Vijayan
in reply to: stanovb


@stanovb wrote:

Thanks, This worked. I am not sure what the "ISOP" is for but i used the chprop command like you said. The other solution looks a little more complicated so i went with this one. Thanks to you both but with my limited knowledge of lisp at this point the simpler the better

Sorry that's my fault.

While testing the code in my system I change the text style name Style-architxt to ISOCP(the one in my computer).

 

Please rename ISOCP in my code to your text style name Style-architxt.

 

 

 

Message 9 of 16
stanovb
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@sovby wrote:

.... I want to run the mtext command a couple of times but ... I want the width factor to be .85


Unless it's changed in newer versions than what I have here, you can apply a width factor to Text entities, but not to Mtext entities as an override of their Style's width factor.  For Text, here's another way to do so after drawing it:

 

(vla-put-ScaleFactor (vlax-ename->vla-object (entlast)) 0.85)

 

But for either Text or Mtext, you could define a Text Style with a width factor of 0.85 built in, and set that current before drawing the Text/Mtext, or don't set that current but change the Style after the fact using (subst)/(entmod) or (vla-put...) methods.


yes, the second option is what i did but all this is good stuff to know. i am trying to teach myself this stuff as i go along & i really do appreciate everyone's help. The guy that does our routines is nearing retirement & i may end up being the person who replaces him with this stuff

Message 10 of 16
Kent1Cooper
in reply to: stanovb


stanovb wrote:

.... The other solution looks a little more complicated so i went with this one. ....


The other solution would look something like this:

 

....

(setq cec (getvar 'cecolor))

(setvar 'cecolor 3)
(COMMAND "TEXT" ....)
(COMMAND "TEXT" ....)
(COMMAND "-MTEXT" ....)
(COMMAND "-MTEXT" ....)

(setvar 'cecolor cec)

....

 

The advantage in terms of code quantity, and probably in terms of speed, though that difference may not be noticeable, is that you don't need to run four separate CHPROP commands.

 

And by the way, you can perform more than one command in one (command) function:

....

(command

  "TEXT" ....

  "TEXT" ....

  "MTEXT" ....

  "MTEXT" ....

); end command

....

 

That would also be faster than getting out of and back into (command) functions repeatedly, though again, for something like this, the difference may not be noticeable.  You could do the same if you chose to stick with CHPROP for handling the color:

....

(command

  "TEXT" ....

  "CHPROP" ....

  "TEXT" ....

  "CHPROP" ....

  "MTEXT" ....

  "CHPROP" ....

  "MTEXT" ....

  "CHPROP" ....

); end command

Kent Cooper, AIA
Message 11 of 16
sovby
in reply to: Kent1Cooper

Thanks for the help

Message 12 of 16
Kent1Cooper
in reply to: sovby


@sovby wrote:

Thanks for the help


You're welcome.  Another thing you should probably add is an error handler [many examples all over this Forum] that will reset the CECOLOR System Variable in the event of some error that would prevent the regular re-setting of it from happening.

Kent Cooper, AIA
Message 13 of 16
sanju.p
in reply to: Kent1Cooper

Hi sir,

 


(defun c:sam()


(setq p1'(10 20))
(setq cec(getvar 'cecolor))
(setvar 'cecolor 3)

(command
"text"p1"50""0""$"
)
)

 

 

when I use above coding

it shows

; error: AutoCAD variable setting rejected: CECOLOR 3

 

Please help me out.

 

Thanks in advance 

Basic Learner.

Message 14 of 16
DannyNL
in reply to: sanju.p

Value should be a string and not a number, like

 

(setvar 'cecolor "3")

 

Message 15 of 16
sanju.p
in reply to: DannyNL

Thank you sir.
Message 16 of 16
Kent1Cooper
in reply to: DannyNL


@DannyNL wrote:

Value should be a string and not a number....


Just to clarify the reason for that....  Though most colors that most people use most often are designated by numbers, it can also accept color names  ["Red" etc.] for the first 7 number values, as well as RGB [and some other types of] designations such as "RGB:130,200,240", and finally, also "BYLAYER" and "BYBLOCK".  So the "type" of the variable has to be a string  to accept all those possibilities, even when the string is just representing a number.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost