assafius Posted September 25, 2012 Share Posted September 25, 2012 Hi, I have a text entity in the model-space. Let's assume that I can retrieve the coordinates of its bounding box perfectly. Now, I have a certain rectangle with a certain size and I wish to insert the text into the rectangle with a good fit. How can lisp something that adjusts the text height to the rectangle's dimensions ? Thanks a lot ! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 25, 2012 Share Posted September 25, 2012 Perhaps use the 'Fit' text alignment, with text height set to the height of the rectangle. As a very simple example, consider: (defun c:tfit ( / a b e p q ) (if (and (progn (while (progn (setvar 'errno 0) (setq e (car (entsel "\nSelect Text: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= 'ename (type e)) (if (/= "TEXT" (cdr (assoc 0 (entget e)))) (princ "\nObject is not Text.") ) ) ) ) ) (= 'ename (type e)) ) (setq e (entget e)) (setq a (getpoint "\nSpecify first corner: ")) (setq b (getcorner a "\nSpecify opposite corner: ")) (setq p (mapcar 'min a b) q (mapcar 'max a b) ) ) (entmod (subst '(72 . 5) (assoc 72 e) (subst '(73 . 0) (assoc 73 e) (subst (cons 10 p) (assoc 10 e) (subst (list 11 (car q) (cadr p) 0.0) (assoc 11 e) (subst (cons 40 (- (cadr q) (cadr p))) (assoc 40 e) e) ) ) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
teknomatika Posted September 26, 2012 Share Posted September 26, 2012 Lee, very good, as expected. By the way, you can apply the same concept to a block? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 26, 2012 Share Posted September 26, 2012 Lee, very good, as expected. Thank you teknomatika. By the way, you can apply the same concept to a block? Are you referring to attributes in blocks? If so, then yes, attributes can also use the 'Fit' alignment. Quote Link to comment Share on other sites More sharing options...
teknomatika Posted September 26, 2012 Share Posted September 26, 2012 Lee, I refer to the block itself. Adjusting a given block to an area defined by a rectangle. Changing its proportions. In the dialog box for insertion of a block i can set the values of x and y. But with this concept would be easier to adjust to a certain area. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 26, 2012 Share Posted September 26, 2012 Adjusting a given block to an area defined by a rectangle. Changing its proportions. Yes, this would certainly be possible by calculating the bounding box of the selected block and changing the X & Y scale factor for the block (providing the block may be scaled non-uniformly) based on the ratio of the width and height of the bounding box to the dimensions of the rectangle specified by the user. Quote Link to comment Share on other sites More sharing options...
assafius Posted September 26, 2012 Author Share Posted September 26, 2012 Ok Lee Thanks. Haven't tried to implement what you wrote in your code yet but it looks promising enough. You write that I might use the 'Fit' command to adjust one height to another, but I think you don't consider the text's width. Two texts can have the same height but if one is longer than the other, it won't fit within the rectangle. Is there a way to fit the text width as well ? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 26, 2012 Share Posted September 26, 2012 You write that I might use the 'Fit' command to adjust one height to another, but I think you don't consider the text's width. Two texts can have the same height but if one is longer than the other, it won't fit within the rectangle. Is there a way to fit the text width as well ? Please re-read my post and study my code, I did not mention the 'Fit' command, whatever that might be. Quote Link to comment Share on other sites More sharing options...
teknomatika Posted September 28, 2012 Share Posted September 28, 2012 Yes, this would certainly be possible by calculating the bounding box of the selected block and changing the X & Y scale factor for the block (providing the block may be scaled non-uniformly) based on the ratio of the width and height of the bounding box to the dimensions of the rectangle specified by the user. Lee, I understood the principles and steps, but obviously my knowledge of AutoLISP are still basic to perform such a routine. So when you have any availability, I'm grateful that you can help (again). Thank you. Quote Link to comment Share on other sites More sharing options...
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.