Jump to content

Text in a box


assafius

Recommended Posts

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 !

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...