Stratos Posted June 1, 2023 Posted June 1, 2023 Hello, I have a code that asks the user to give text (text1) and select two points (p1 and p2). If the text length is larger than the x distance between these two points, the code should change the width factor of the text to make it smaller than this distance. Is it possible? Here is my code so far , pretty much nothing since I am stuck... (setq p1 (getpoint "\nFirst point ")) (setq p2 (getcorner p1 "\nOpposite point ")) (setq text1 (getstring T "\nEnter text:")) Quote
Steven P Posted June 1, 2023 Posted June 1, 2023 (edited) So I guess the next stage is to calculate the width of the text in 'standard' for - no new width factor? Something similar came up earlier today to use a bounding box around some text, and here Lee Macs Bounding Box LISP can work (you'll find it with a simple internet search) - if you remove the part that draws the box but get the coordinates of points 1 and 2 - following his example and some thinking. If the text is at an angle you could look to his BT (text Box) LISP which does the same but for texts at an angle. Again points 1 and 2. Should work out the distance from them and also distance of the 2 selected points - and from that can work out if you need to apply a width factor? Is that enough to frustrate you but make something up or do you want a more finished code? (Busy in work at the moment to make something up for you) Edited June 1, 2023 by Steven P Quote
Stratos Posted June 1, 2023 Author Posted June 1, 2023 How do I apply the width factor I want e.g 0.7? I use this command to write my text: (setq PT3 (list 0 0 0)) (command "_text" "m" "c" PT3 "1" "0" "lalalalala") Quote
marko_ribar Posted June 1, 2023 Posted June 1, 2023 (edited) (command "_.text" "_j" "_m" "_non" (list 0.0 0.0 0.0) "1.0" "0.0" "lalalalala") (setpropertyvalue (entlast) "WidthFactor" 0.7) Edited June 1, 2023 by marko_ribar 1 Quote
Steven P Posted June 1, 2023 Posted June 1, 2023 (edited) If you look at 'entmod' to change the text, create your text as above. Example here based on AutoCAD help (select an entity to change), assoc 41 is for width factor (setq ed (entget (car (entsel)))) (setq ed (subst (cons 41 -NEWWIDTHFACTOR-) (assoc 41 ed) ed )) (entmod ed) though in your case (using entlast - the last entity) (setq ed (entget (entlast))) (setq ed (subst (cons 41 -NEWWIDTHFACTOR-) (assoc 41 ed) ed )) (entmod ed) (though it is slightly more efficient to use entmake to create the whole text including width factor, if it works this way, it works) EDIT Marko_Ribar is of course correct, however this way can be used on existing texts as the first snippet - so place the text, find bounding box area, alter width using entmod Edited June 1, 2023 by Steven P 1 Quote
mhupp Posted June 1, 2023 Posted June 1, 2023 6 hours ago, Steven P said: Something similar came up earlier today to use a bounding box around some text, and here Lee Macs Bounding Box LISP can work (you'll find it with a simple internet search) - if you remove the part that draws the box but get the coordinates of points 1 and 2 - following his example and some thinking. use textbox command. 1 Quote
Steven P Posted June 2, 2023 Posted June 2, 2023 (edited) Thanks - that's a new command for me. Edit: For my reference later (textbox (list (assoc 1 (entget (car (entsel)))))) Edited June 2, 2023 by Steven P Quote
marko_ribar Posted June 3, 2023 Posted June 3, 2023 (edited) Should work as desired... (defun c:txtby2pts ( / p1 p2 txt txtbox v w h ) (initget 1) (setq p1 (getpoint "\nFirst point : ")) (initget 1) (setq p2 (getcorner p1 "\nSecond point : ")) (setq txt (getstring t "\nText : ")) (vl-cmdf "_.text" "_j" "_l" "_non" p1 1.0 0.0 txt) (setq txtbox (textbox (list (assoc 1 (entget (entlast)))))) (setq v (mapcar '- p2 p1)) (setq w (car v) h (cadr v)) (vl-cmdf "_.scale" (entlast) "" "_non" p1 h) (setpropertyvalue (entlast) "WidthFactor" (/ (/ w h) (- (caadr txtbox) (caar txtbox)))) (princ) ) HTH. M.R. Edited June 3, 2023 by marko_ribar 2 Quote
marko_ribar Posted June 3, 2023 Posted June 3, 2023 If you need to write text in UCS/=WCS at some 3D angle, you should firstly align view to UCS with PLAN command... Next step is start and write text with above posted code... Regards, M.R. Quote
Stratos Posted June 3, 2023 Author Posted June 3, 2023 18 hours ago, Steven P said: If you look at 'entmod' to change the text, create your text as above. Example here based on AutoCAD help (select an entity to change), assoc 41 is for width factor (setq ed (entget (car (entsel)))) (setq ed (subst (cons 41 -NEWWIDTHFACTOR-) (assoc 41 ed) ed )) (entmod ed) though in your case (using entlast - the last entity) (setq ed (entget (entlast))) (setq ed (subst (cons 41 -NEWWIDTHFACTOR-) (assoc 41 ed) ed )) (entmod ed) (though it is slightly more efficient to use entmake to create the whole text including width factor, if it works this way, it works) EDIT Marko_Ribar is of course correct, however this way can be used on existing texts as the first snippet - so place the text, find bounding box area, alter width using entmod This was pure gold. Thank you very much!!!! 1 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.