rectangular frame around a text

rectangular frame around a text

Anonymous
Not applicable
3,935 Views
4 Replies
Message 1 of 5

rectangular frame around a text

Anonymous
Not applicable

Hello everyone,

Can you help me with a lisp that after selecting some objects it will create a frame around it (like the example).

2019-01-10_15-25-51.jpg

very similar to the lisp entitled "TEXTBOX" , but I want that after calling the lisp it will allow to select items,  and the default offset will be 0.35mm.

The textbox lisp work like that:

It will be enabling the user to create a 2D polyline
rectangular frame around selected Text & MText objects, with a
user-defined offset. (The default is 0.35mm) .

And I want it to allow me to select either one single text and some entities.

Thank you,

Eyal

 

Here is the textbox lisp for indication:

;;----------------------------=={ Box Text }==--------------------------;;
;;                                                                      ;;
;;  This program performs in much the same way as the Express Tools'    ;;
;;  'TCircle' command: enabling the user to create a 2D polyline        ;;
;;  rectangular frame around selected Text & MText objects, with a      ;;
;;  user-defined offset.                                                ;;
;;                                                                      ;;
;;  Upon issuing the command syntax 'BT' at the AutoCAD command-line,   ;;
;;  the program first prompts the user to specify an offset factor      ;;
;;  for the text frame. This factor is multiplied by the text height    ;;
;;  for every selected text object to determine the offset of the       ;;
;;  rectangular frame from the text. At this prompt, the last used      ;;
;;  value is available as a default option.                             ;;
;;                                                                      ;;
;;  The program then prompts the user to make a selection of text       ;;
;;  and/or mtext objects. Following a valid selection, the program      ;;
;;  iterates over the selection and constructs a rectangular frame      ;;
;;  surrounding each object, offset by a distance determined by the     ;;
;;  given offset factor. The generated text box will inherit the        ;;
;;  basic properties of the enclosed text object (e.g. Layer, Linetype, ;;
;;  Lineweight etc.).                                                   ;;
;;                                                                      ;;
;;  The program will also perform successfully with Text or MText       ;;
;;  defined in any construction plane, and under all UCS & view         ;;
;;  settings.                                                           ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2010  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.2    -    2015-02-22                                      ;;
;;----------------------------------------------------------------------;;

(defun c:bt ( / *error* def enx idx lst off sel )

    (defun *error* ( msg )
        (LM:endundo (LM:acdoc))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (if (or (not (setq def (getenv "LMac\\boxtext-off")))
            (not (setq def (distof def 2)))
        )
        (setenv "LMac\\boxtext-off" (rtos (setq def 0.35) 2 2))
    )
    (initget 4)
    (if (setq off (getreal (strcat "\nSpecify offset factor <" (rtos def 2 2) ">: ")))
        (setenv "LMac\\boxtext-off" (rtos off 2 2))
        (setq off def)
    )
    
    (LM:startundo (LM:acdoc))
    (if (setq sel (LM:ssget "\nSelect text or mtext <exit>: " '(((0 . "TEXT,MTEXT")))))
        (repeat (setq idx (sslength sel))
            (setq enx (entget (ssname sel (setq idx (1- idx))))
                  lst (text-box-off enx (* off (cdr (assoc 40 enx))))
            )
            (entmake
                (append
                   '(
                        (000 . "LWPOLYLINE")
                        (100 . "AcDbEntity")
                        (100 . "AcDbPolyline")
                        (090 . 4)
                        (070 . 1)
                    )
                    (LM:defaultprops enx)
                    (list (cons  038 (caddar lst)))
                    (mapcar '(lambda ( x ) (cons 10 x)) lst)
                    (list (assoc 210 enx))
                )
            )
        )
    )
    (LM:endundo (LM:acdoc))
    (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget arg))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)

;; Default Properties  -  Lee Mac
0 Likes
Accepted solutions (1)
3,936 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

As I understand you, the only thing you what, is swap the order of selecting and specifying a frame offset...

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi @ВeekeeCZ ,

It gives :

 1.jpg 

like shown in the left , and should be like the picture in the right.

I want the rectangle to be with offset to the boundary enclosed all the selected entities.

Thank you,

Eyal

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... Can you help me with a lisp that after selecting some objects it will create a frame around it (like the example).  ....  with a user-defined offset. (The default is 0.35mm) .

And I want it to allow me to select either one single text and some entities.

....


 

Modifying something I already had to draw the bounding box around multiple objects [of any kind(s), but without the offset], now restricted to Text/Mtext and with offset:

;|
FrameText.lsp [command name: FT]
To draw a Frame around single or multiple Text/Mtext objects. Finds overall
  extentof object(s) selected, draws a Rectangle around that collective box, and
  Offsets it outboard by User-specified distance.
Works in non-World UCS if XYZ axes parallel to WCS [i.e. origin may
  be different but with same orientation].
Kent Cooper, 10 January 2019
|;
(defun C:FT (/ ss minpt maxpt eLL eUR LL UR robj); = Frame Text
  (setq *FTdist* ; global variable
    (cond
      ( (getdist
          (strcat
            "Frame offset <"
            (if *FTdist* (rtos *FTdist*) "0.35"); offer initial default if no prior value
            ">: "
          ); strcat
        ); getdist
      ); User-input condition
      (*FTdist*); prior value default on Enter if present
      (0.35); initial default on Enter if no prior value
    ); cond
  ); setq
  (prompt "\nTo draw a Frame around Text/Mtext object(s),")
  (if (setq ss (ssget '((0 . "*TEXT"))))
    (progn ; then
      (repeat (setq n (sslength ss))
        (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 'minpt 'maxpt)
        (setq
          eLL (vlax-safearray->list minpt)
          eUR (vlax-safearray->list maxpt)
          LL (if LL (mapcar 'min eLL LL) eLL)
          UR (if UR (mapcar 'max eUR UR) eUR)
        ); setq
      ); repeat
      (command "_.rectangle" "_none" (trans LL 0 1) "_none" (trans UR 0 1))
      (setq robj (vlax-ename->vla-object (entlast)))
      (vla-offset robj *FTdist*)
      (vla-delete robj); delete no-offset initial rectangle
    ); progn
    (prompt "\nNothing selected."); else
  ); if
  (princ)
); defun
(vl-load-com)
(prompt "\nType FT to draw a Frame around Text/Mtext object(s).")

It assumes your drawing unit is a millimeter.  If it's not, change the initial default value [which is in drawing units] to compensate. 

Kent Cooper, AIA
Message 5 of 5

Anonymous
Not applicable

Thank you @Kent1Cooper and thank you @ВeekeeCZ

@Kent1Cooper it works great!

 

0 Likes