antistar Posted September 10, 2010 Posted September 10, 2010 Hi to all. I have drawings with texts of different heights from the heights of styles to which they belong. Does anyone have a routine that changes the height of all texts to match its respective style? Quote
alanjt Posted September 10, 2010 Posted September 10, 2010 You can retrieve the respective text size for each style with (cdr (assoc 40 (tblsearch "STYLE" "StyleName"))) From there, you modify the height of each text matching that style. Quote
antistar Posted September 10, 2010 Author Posted September 10, 2010 Alan, thanks for your reply. I need to do this for all the texts of the drawings at once. Change the height of all the texts to the correct height of their respective styles. You know how to do this? Quote
alanjt Posted September 10, 2010 Posted September 10, 2010 Step through the text (ssget "_X" '((0 . "TEXT"))), get the textstyle from an entget dump and get the respective height with the above posted code. Quote
antistar Posted September 11, 2010 Author Posted September 11, 2010 Alan, I guess I am not experienced enough to know which command to use. Can you help me with a code to select all text and update the height of spring to the height of style to which he belongs? Thanks in advance. Quote
Lee Mac Posted September 11, 2010 Posted September 11, 2010 Here's how to go about it: Get a SelectionSet of Text and/or MText using the selection set with filter as Alan has demonstrated. Step through this SelectionSet using ssname with a counter to get at each entity in the set in turn. Get hold of DXF code 7 (TextStyle) using just functions as entget, assoc and cdr and use the code provided by Alan above to get retrieve the Text height for the entity for this style. Use such functions as subst, cons and entmod to modify the text height of the entity. Use princ to exit cleanly. Quote
Tharwat Posted September 11, 2010 Posted September 11, 2010 Are you planning to change all texts of a drawing to specific height ? Tharwat Quote
David Bethel Posted September 11, 2010 Posted September 11, 2010 You know, sometimes it is just easier and less work just to post the code. And the good ones actually learn from it. Quote
antistar Posted September 11, 2010 Author Posted September 11, 2010 I have drawings with texts of which are style name correct but the height is wrong. I just want to do an update on the value of the height of all texts. This value must be equal to the style to which it belong. Quote
Lee Mac Posted September 11, 2010 Posted September 11, 2010 You know, sometimes it is just easier and less work just to post the code. And the good ones actually learn from it. Are you referring to me posting the code? I just didn't want to hand over the solution but rather 'teach a man to fish'... Quote
JohnM Posted September 11, 2010 Posted September 11, 2010 i do agree with lee but i was board, so here is a fish please learn something note: if you have a style that has a heigth of 0.0 then nothing will be done. (defun c:txcng (/ sty stlst ht txss cnt ssl ent) ;;; get text styles (vlax-for sty (vla-get-textstyles (vla-get-ActiveDocument (vlax-get-Acad-Object) );_get doc );_text collection (setq stlst (cons (vla-get-Name Sty) stlst));_style list );_end for ;;; go thru list to change heights (foreach item stlst (setq ht (cdr(assoc 40 (tblsearch "Style" item))));_get original heigth (if (> ht 0.0);_as long as no zero heigth (progn (setq txss (ssget "_X" (list(cons 0 "mtext,text")(cons 7 item))));-get all text for that style (if txss ;_if there is text (progn (setq cnt 0);_counter (setq ssl (sslength txss));_# of items in selection set (while (< cnt ssl) (setq snm (ssname txss cnt));_get entity name (setq ent (entget snm));_get entity info (if (/=(cdr(assoc 40 ent))ht);_if heigth id not = to original style ht (progn (setq ent (subst (cons 40 ht) (assoc 40 ent) ent));_put in new heigth (entmod ent);_update entity );_progn );_if (setq cnt (1+ cnt));_up counter by 1 );_while );_progn );_if );_progn );_if );_foreach (princ) );_defun Quote
Tharwat Posted September 11, 2010 Posted September 11, 2010 Hello JohnM. Your codes are really great, but if the user does not have (vl-load-com) in their system, it would fail . Thank you. Tharwat Quote
JohnM Posted September 11, 2010 Posted September 11, 2010 oops i forgot, it's beer time here so it's the beers fault. Bad Bud! Bad Bud! thanks Quote
Lee Mac Posted September 12, 2010 Posted September 12, 2010 Here's another fish in that case, hopefully pretty efficient: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] [color=black]c:TextHeightByStyle[/color] [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] l def [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac 2010[/color][/i] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] data [b][color=BLUE]/[/color][/b] x i ss e [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] data[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=#009900]-1[/color][/b] data [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] data[b][color=RED])[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_X"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#a52a2a]"TEXT,MTEXT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]7[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] x[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]-4[/color][/b] [b][color=#a52a2a]"!="[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]40[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] x[b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] e [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED]))))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entupd[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]-1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]40[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] x[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]40[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] e[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] e[b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] def [b][color=RED]([/color][/b][b][color=BLUE]tblnext[/color][/b] [b][color=#a52a2a]"STYLE"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]null[/color][/b] def[b][color=RED])))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] l [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]2[/color][/b] def[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]40[/color][/b] def[b][color=RED])))[/color][/b] [b][color=#009900]42[/color][/b] [b][color=#009900]40[/color][/b][b][color=RED])[/color][/b] def [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] l [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote
David Bethel Posted September 12, 2010 Posted September 12, 2010 And another: [color=#8b4513];;;CHANGE TEXT ENTITY HEIGHTS TO TEXT STYLE TABLE HEIGHT[/color] [b][color=BLACK]([/color][/b]defun c:txt-shgt [b][color=FUCHSIA]([/color][/b]/ tdef style_name ss i ent_name ent_def[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq tdef [b][color=MAROON]([/color][/b]tblnext [color=#2f4f4f]"STYLE"[/color] [b][color=GREEN]([/color][/b]not tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq style_name [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 2 tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 7 style_name[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq i -1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq ent_name [b][color=BLUE]([/color][/b]ssname ss [b][color=RED]([/color][/b]setq i [b][color=PURPLE]([/color][/b]1+ i[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq ent_def [b][color=BLUE]([/color][/b]entget ent_name[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]assoc 40 tdef[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 40 ent_def[b][color=RED])[/color][/b] ent_def[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Lee, I guess that it is debatable as to how to teach someone to fish. Do students learn better by: seeing elementary examples ( hopefully either well documented or formatted in an easily followed style ) being guided to reference materials given a flow chart of logic to follow I guess it boils down to how much knowledge the student has already acquired. I normally to assume a newbie to novice. Otherwise they wouldn't have made a request for what is to us a simple routine. When I see something way over my head, I tend not to try to dissect it to the nth level. If it is just a little over, then I'll invest the time to fulling understand the code. My $0.02 -David Quote
stevesfr Posted September 12, 2010 Posted September 12, 2010 I learn quickest from the following concept: **seeing elementary examples ( hopefully either well documented or formatted in an easily followed style** And it sure sinks in the best for me.... just my $.02 Steve Quote
Lee Mac Posted September 12, 2010 Posted September 12, 2010 I see your point David, but I've been frowned upon in the past for straightaway handing out a complete solution, as many just take the code blindly - hence my attempt at a different approach. I do prefer to just write the code however, as it is a lot more work trying to direct someone towards the solution. Lee Quote
David Bethel Posted September 12, 2010 Posted September 12, 2010 The question would be ' What is your motive or goal? ' Is it to improve or practice your own skills? Is it to teach? Is it to learn? Is it to brag? Is it to be helpful or charitable? We all have our different reasons for being here. It is always acceptable to pass up on a request if you believe you are being taken advantage of. Because CadTutor is a learning oriented site, I tend to lean toward contributing fundamental stuff focused more or less at a beginner. It helps to keep my skills a little sharper. We all probably need to do better at commenting or at least describing the general gist of a snippet so everyone can have a chance at learning. Of coarse there are always the elaborate, deeply nested, highly evolved snippet that we think is the cat's meow, but is gibberish to the average coder. -David Quote
David Bethel Posted September 12, 2010 Posted September 12, 2010 I learn quickest from the following concept:**seeing elementary examples ( hopefully either well documented or formatted in an easily followed style** And it sure sinks in the best for me.... just my $.02 Steve Steve, I agree that samples or snippets are my choice in learning environment. I learned by dissecting the code that came with AutoCAD in Release 9 & 10. It wasn't until Compuserve came around in the early 90s that you could find a peer to peer forum about autocad. I envy the newbies today with things like the forums here and Afralisp. It is so much better than trying to slog through an instruction manual. My $0.04 -David Quote
antistar Posted September 13, 2010 Author Posted September 13, 2010 Alan, David, Lee and John... Thank you for the support of all was a very helpful teaching that solved my problem entirely. Quote
Recommended Posts
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.