Jump to content

How to fit a mtext?


masoud_123

Recommended Posts

I was wondering if it is possible to fit mtext entity in a place by knowing the height and width of that place?

How we can adjust mtext height to fit in that place in entmake mtext?

(entmake
 (list
	'(0 . "MTEXT")
	'(102 . "{ACAD_REACTORS")
	'(102 . "}")
	'(100 . "AcDbEntity")
	'(100 . "AcDbMText")
	 (cons 10 insertion_point)
	(cons 40 text_height)
               (cons 62 4)
	(cons 41 refrence_rectangle_width)
	'(42 . 2.55)
	'(43 . 0.18)
	'(44 . 1.0)
	'(71 . 5)
	'(72 . 1)
	(cons 1  "Your string hear")
	'(7 . "Text Style")
	'(210 0.0 0.0 1.0)
	'(11 1.0 0.0 0.0)
	'(50 . 0.0)
	'(73 . 1)
        )
 )

Link to comment
Share on other sites

I was wondering if it is possible to fit mtext entity in a place by knowing the height and width of that place?

How we can adjust mtext height to fit in that place in entmake mtext?

only for single line

 

hi masoud_123,

welcome to the forum :)

 

i hope this textbox factor makes sense?

 

(defun [color="blue"]Mtext_fit[/color] (pt str / doc bb)
 ;hanhphuc 26/11/2014
 (setq	doc (vlax-get-acad-object)
       [color="red"]str (substr str 1 (vl-string-search "\\" str))  ;<-- added[/color]   
bb  (apply 'mapcar
	   (cons '- (reverse (mapcar ''((x) (cdr (reverse x))) (textbox (list (cons 1 str))))))
	   ) ;_ end of apply
) ;_ end of setq
 (vla-AddMText
   (foreach x '(ActiveDocument ActiveLayout Block) (setq doc (vlax-get doc x)))
   (vlax-3d-point pt)
   (* (car bb) (apply '/ (reverse bb)))
   str
   ) ;_ end of vla-AddMText
 ) ;_ end of defun

 

Test

(defun c:test (/ *error* pt str var)
 (set'var (getvar 'dynmode))
 (defun *error* (msg)
   (if	var
     (setvar 'dynmode var)
     ) ;_ end of if
  (princ ":-(")
   ) ;_ end of defun
 (if (and (setq pt (getpoint "\nInsertion Point.."))
   (setvar 'dynmode 1)
   (setq str (getstring "\nInput text:  " t))
   (setvar 'dynmode var)
   ) ;_ end of and
   ([color="blue"]Mtext_fit[/color] pt str)
   ) ;_ end of if
 (princ)
 ) ;_ end of defun

 

Though the above example not entmake method,

The width factor is same.

Use the example above to addMtext,

then entget compare the textbox with dxf index 41,42,43

I think you can figure it out

Try it :)

 

HTH

Edited by hanhphuc
substr
Link to comment
Share on other sites

Only little hiccup is that Fonts are all different in terms of their width and height ratio so may work with one style and not quite with another, also if they start kerning then a different problem again.

Link to comment
Share on other sites

Only little hiccup is that Fonts are all different in terms of their width and height ratio so may work with one style and not quite with another, also if they start kerning then a different problem again.

 

Thanks BIGAL. you are correct, this only for single line also not 100%.

the different font or formatted string may not work correctly

 

By adding this, it only skips "\\after slash is ignore"

(substr str 1 (vl-string-search "\\" str))

 

example:

([color="blue"]Mtext_fit[/color] (getpoint) "FORMATED MTEXT:\\P\\pi-9.5,l1.5,t9.5;")
;then this will fit to "FORMATED MTEXT:"

 

By manually fitting single or multi-lines,

just type & *copy text contents in notepad then, in acad space right click-> paste ,or Crtl+v

*automatically paste as Mtext

i maybe wrong, just my $0.02 :)

Edited by hanhphuc
edit: *
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...