This is a nice program, Bobby. The problem is the box ir right outside the text. I was wondering if the program could be modified so the box is offset with let's say, 0.35 or 0.5 x Text Height. I was trying to get pt1 and pt2 coordinates to start with that, but it didn't work out. Do you think you could help?
Thank you.
@HS20EXR wrote:This is a nice program, Bobby. The problem is the box ir right outside the text. I was wondering if the program could be modified so the box is offset with let's say, 0.35 or 0.5 x Text Height. ....
Bobby may not still be checking in after all these years. Here's a modification/adjustment that does that:
(defun C:TBOX (/ vlaText pt1 pt2 vlaRect)
(vl-load-com)
(setq vlaText (vlax-ename->vla-object (car (entsel "\nSelect text: "))))
(vla-getboundingbox vlaText 'pt1 'pt2)
(command ".rectangle" (vlax-safearray->list pt1) (vlax-safearray->list pt2))
(setq vlaRect (vlax-ename->vla-object (entlast)))
(vla-offset vlaRect (* (vla-get-Height vlaText) 0.35)); <--- or 0.5
(vla-delete vlaRect)
)
However, I would greatly prefer a modification of Jurg Menzi's routine, for several reasons:
1) If the Text isn't orthogonally oriented, the Rectangle follows the Text angle rather than being orthogonal;
2) It does any number of Text objects at once, instead of needing to be invoked for each one;
3) You can select the Text objects either before or after invoking the command;
4) It controls for object type in the selection;
5) It's already built to Offset the Rectangle from the Text.
Here's a modification of that:
(defun C:TextBox
(/ CurSet CurEnt EntCnt PntLst RecEnt OffDst OffPnt OldCmd OldUci OldUcf)
(setq CurSet
(cond
((ssget "_I" '((0 . "TEXT"))))
(T (prompt "\nTo put boxes around Text,") (ssget '((0 . "TEXT"))))
); cond
); setq
(if CurSet
(progn
(setq
OldCmd (getvar "CMDECHO")
OldUci (getvar "UCSICON")
OldUcf (getvar "UCSFOLLOW")
EntCnt 0
); setq
(setvar "CMDECHO" 0)
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_.UNDO" "_GROUP")
)
(setvar "UCSICON" 0)
(setvar "UCSFOLLOW" 0)
(repeat (sslength CurSet)
(setq
CurEnt (ssname CurSet EntCnt)
CurEntD (entget CurEnt)
EntCnt (1+ EntCnt)
)
(command "_.UCS" "_OBJ" CurEnt)
(setq
PntLst (textbox CurEntD)
OffPnt (polar (cadr PntLst) 0 1)
OffDst (* (cdr (assoc 40 CurEntD)) 0.35) ;Distance Text -> Rectangle <--- or 0.5
); setq
(command "_.RECTANGLE" (car PntLst) (cadr PntLst))
(setq RecEnt (entlast))
(command
"_.OFFSET" OffDst RecEnt OffPnt ""
"_.ERASE" RecEnt ""
"_.UCS" "_PRE"
); command
); repeat
(setvar "UCSICON" OldUci)
(setvar "UCSFOLLOW" OldUcf)
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_.UNDO" "_END")
); if
(setvar "CMDECHO" OldCmd)
); progn
); if
(princ)
); defun
Either of them could also be done in a way that doesn't pre-define the percentage of the Text height that you want the Rectangle offset from it, but either as routines that take an argument for the percentage, or to ask the User for that percentage.
@pbejse wrote:An alternative:
If you have Express Tools
command: Tcircle
I am aware of this command in Express Tools, it works nicely and gives a few options but it requires too much input from the user, I was looking for something simple and quick that needs minimum input. I was trying to write a lisp that skips a few steps in the commands, so it asks for less input, something like
(command "tcircle" pause "rectangle" "variable" "" "") ...
so I would need only to invoke the command and select the text and hit ENTER but when trying to run it says "Unknown command Tcircle ... " for some reason. I guess because it's an Express Tool command. What do you think?
Thank you, pbejse.
Thank you very much for the programs, Master Cooper.
I will try them on Tuesday when I go to work. The first program will do for me 90% of the time, I think, I like it because it draws the rectangle as soon as the I select the text, doesn't require to hit ENTER, I usually don't need to box more than one text object at a time. And I like to have the percentage of the Text height that I want the Rectangle offset from pre-defined because I will probably never change it. If I want, I can modify the program for that. I will use the second program for situations where the other one doesn't work.
I also want to modify the programs to cloud text, actually this was the goal when I started looking for a LISP that draws Rectangle around text, so I can use revcloud command to turn the Rectangle into cloud. I think it's going to be easy, especially for the first program, for the second one I was thinking to add revcloud command here
[.....]
"_.OFFSET" OffDst RecEnt OffPnt ""
"_.ERASE" RecEnt ""
"_.UCS" "_PRE"
); command
(command "REVCLOUD" "" "L" "")
); repeat
(setvar "UCSICON" OldUci)
(setvar "UCSFOLLOW" OldUcf)
(if (= (logand (getvar "UNDOCTL") 4) 4)
[....]
I hope it works, is there another method you would suggest?
I appreciate your help.
@HS20EXR wrote:
(command "tcircle" pause "rectangle" "variable" "" "") ...
so I would need only to invoke the command and select the text and hit ENTER but when trying to run it says "Unknown command Tcircle ... " for some reason. I guess because it's an Express Tool command. What do you think?
Thank you, pbejse.
vla-sendcommand <-----
(defun c:Test (/ ss)
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(progn (sssetfirst nil ss)
(vla-sendcommand
(cond (aDoc)
((setq aDoc
(vla-get-activedocument
(vlax-get-acad-object))))
)
"_.TCIRCLE 0.3 RECTANGLES VARIABLE "
)
)
)
(princ)
)
HTH
Awesome! Thank you, it work very well.
Is there a way to add revcloud command to turn the rectangles into clouds if multiple text objects are selected?
Jurg Menzi's routine modification has the advantages you mentioned, unfortunately has one big drawback, works for TEXT only, not for MTEXT.