Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Text box lisp . . .

21 REPLIES 21
Reply
Message 1 of 22
Anonymous
3473 Views, 21 Replies

Text box lisp . . .

Some time back I had a lisp routine that when you picked a single piece of
text, even a sentence, it would draw a box (polyline) around the text.

Anyone have one of those that they'd like to share?

Thanks-
21 REPLIES 21
Message 2 of 22
Anonymous
in reply to: Anonymous

Quick and Dirty... No Error checking. This does require that you have
express tools loaded.

(defun C:BoxText (/ tbox)
(setq Tbox (acet-geom-textbox (entget (car (entsel))) 0))
(command ".rectangle" (nth 0 Tbox) (nth 2 Tbox))
(princ)
);defun

-Jason

"Tom C." wrote:
>
> Some time back I had a lisp routine that when you picked a single piece of
> text, even a sentence, it would draw a box (polyline) around the text.
>
> Anyone have one of those that they'd like to share?
>
> Thanks-
Message 3 of 22
Anonymous
in reply to: Anonymous

doesnt that need to have express tools loaded??

Jason Piercey wrote:
>
> Quick and Dirty... No Error checking. This does require that you have
> express tools loaded.
>
> (defun C:BoxText (/ tbox)
> (setq Tbox (acet-geom-textbox (entget (car (entsel))) 0))
> (command ".rectangle" (nth 0 Tbox) (nth 2 Tbox))
> (princ)
> );defun
>
> -Jason
>
> "Tom C." wrote:
> >
> > Some time back I had a lisp routine that when you picked a single piece of
> > text, even a sentence, it would draw a box (polyline) around the text.
> >
> > Anyone have one of those that they'd like to share?
> >
> > Thanks-

--

-------------------
Nauman M
CAD Bazaar
Need to easily Navigate to your Custom Content Folders?
Need Autolayering for Dimensions without going through Design Center?
Download the updated ADT Tools for ADT 2 & 3 at
http://www.cadbazaar.com
Message 4 of 22
Anonymous
in reply to: Anonymous

I have something you could easily modify. TEXTBOX puts a solid behind the
text. I use this for 0% graying in order to hide what's behind the text.
If Express Tools "mask" command worked right, I would use it. TEXTTRIM
draws that needed polyline and trims any entities under the text. Not
perfect, but you could easily modify these routines for your use.

Hope it helps.

(defun C:TEXTBOX (/ count sstext textent tb ll ur ul lr tf)
(setvar "osmode" 0)
(setq CURRENTLAYER (getvar "CLAYER"))
(command "_.undo" "Begin")
(command "_.layer" "m" "HIDE-TEXT" "c" "8" "" "")
(setq SSTEXT (ssget '((0 . "TEXT"))))
(setq COUNT 0)
(if SSTEXT
(while (< COUNT (sslength SSTEXT))
(setq textent (cdr (car (entget (ssname SSTEXT COUNT)))))
(command "_.ucs" "Object" textent)
(setq tb (textbox (list (cons -1 textent)))
ll (car tb)
ur (cadr tb)
tf (/ (- (cadr ur) (cadr ll)) 6)
ul (list (- (car ll) tf) (+ (cadr ur) tf))
lr (list (+ (car ur) tf) (- (cadr ll) tf))
ll (list (- (car ll) tf) (- (cadr ll) tf))
ur (list (+ (car ur) tf) (+ (cadr ur) tf))
)
(command "_.solid" ll lr ul ur "")
(command "_.copy" textent "" "0,0" "0,0")
(command "_.erase" "p" "")
(command "_.ucs" "p")
(setq COUNT (1+ COUNT))
)
)
(command "_.undo" "End")
(setvar "CLAYER" CURRENTLAYER)
(princ)
)

(defun C:TEXTTRIM (/ count sstext textent tb ll ur ul lr tf)
(setvar "osmode" 0)
(setq CURRENTLAYER (getvar "CLAYER"))
(command "_.undo" "Begin")
(command "_.layer" "m" "HIDE-TEXT" "c" "8" "" "")
(setq SSTEXT (ssget '((0 . "TEXT"))))
(setq COUNT 0)
(if SSTEXT
(while (< COUNT (sslength SSTEXT))
(setq textent (cdr (car (entget (ssname SSTEXT COUNT)))))
(command "_.ucs" "Object" textent)
(setq tb (textbox (list (cons -1 textent)))
ll (car tb)
ur (cadr tb)
tf (/ (- (cadr ur) (cadr ll)) 6)
ul (list (- (car ll) tf) (+ (cadr ur) tf))
lr (list (+ (car ur) tf) (- (cadr ll) tf))
ll (list (- (car ll) tf) (- (cadr ll) tf))
ur (list (+ (car ur) tf) (+ (cadr ur) tf))
)
(command "_.pline" ll lr ur ul "c")
(setq TOFFSET (* (distance ll ur) 0.20))
(command "_.trim" (setq THETRIMLINE (entlast)) "" "f" ll ur "" "")
(command "_.erase" THETRIMLINE "")
(command "_.ucs" "p")
(setq COUNT (1+ COUNT))
)
)
(command "_.undo" "End")
(setvar "CLAYER" CURRENTLAYER)
(princ)
)

"Tom C." wrote in message
news:F2716F8F1A6DF92ED16212168E98FCB4@in.WebX.maYIadrTaRb...
> Some time back I had a lisp routine that when you picked a single piece of
> text, even a sentence, it would draw a box (polyline) around the text.
>
> Anyone have one of those that they'd like to share?
>
> Thanks-
>
Message 5 of 22
Anonymous
in reply to: Anonymous

See customer files for boxtext, see file for credits.

"Tom C." wrote in message
news:F2716F8F1A6DF92ED16212168E98FCB4@in.WebX.maYIadrTaRb...
> Some time back I had a lisp routine that when you picked a single piece of
> text, even a sentence, it would draw a box (polyline) around the text.
>
> Anyone have one of those that they'd like to share?
>
> Thanks-
>
Message 6 of 22
Anonymous
in reply to: Anonymous

Yes it does. (see my first post).

-Jason

Nauman M wrote:
>
> doesnt that need to have express tools loaded??
>
> Jason Piercey wrote:
> >
> > Quick and Dirty... No Error checking. This does require that you have
> > express tools loaded.
> >
> > (defun C:BoxText (/ tbox)
> > (setq Tbox (acet-geom-textbox (entget (car (entsel))) 0))
> > (command ".rectangle" (nth 0 Tbox) (nth 2 Tbox))
> > (princ)
> > );defun
> >
> > -Jason
> >
> > "Tom C." wrote:
> > >
> > > Some time back I had a lisp routine that when you picked a single piece of
> > > text, even a sentence, it would draw a box (polyline) around the text.
> > >
> > > Anyone have one of those that they'd like to share?
> > >
> > > Thanks-
>
> --
>
> -------------------
> Nauman M
> CAD Bazaar
> Need to easily Navigate to your Custom Content Folders?
> Need Autolayering for Dimensions without going through Design Center?
> Download the updated ADT Tools for ADT 2 & 3 at
> http://www.cadbazaar.com
Message 7 of 22
Anonymous
in reply to: Anonymous

customer files?
where?

"Chip Harper" wrote in message
news:DAE0C42B0B363780C8A6615BE59B8F20@in.WebX.maYIadrTaRb...
> See customer files for boxtext, see file for credits.
>
> "Tom C." wrote in message
> news:F2716F8F1A6DF92ED16212168E98FCB4@in.WebX.maYIadrTaRb...
> > Some time back I had a lisp routine that when you picked a single piece
of
> > text, even a sentence, it would draw a box (polyline) around the text.
> >
> > Anyone have one of those that they'd like to share?
> >
> > Thanks-
> >
>
Message 8 of 22
Anonymous
in reply to: Anonymous

"Customer Files" is the seperate area where we post files .... here is the
link if you are using a news reader ...

news://discussion.autodesk.com/autodesk.autocad.customer-files

if you are accessing from the web side (via a browser) use the search
feature to find it as I don't know the url.

"Tom C." wrote in message
news:7347E6F4B051994ACE52E4B5C55DD839@in.WebX.maYIadrTaRb...
> customer files?
> where?
Message 9 of 22
Anonymous
in reply to: Anonymous

Then there is the ever popular and easy to read ActiveX way.

(defun c:tbox ()
(vl-load-com)
(dbox
(vlax-ename->vla-object (car (entsel "\nSelect text: ")))
)
)

(defun dbox (vlaTextObj / pt1 pt2)
(vla-getboundingbox vlaTextObj 'pt1 'pt2)
(command ".rectangle" (vlax-safearray->list pt1) (vlax-safearray->list
pt2))
)

Short and sweet and doesn't depend on express tools which you may or may not
have in the future.
--
Bobby C. Jones

"Tom C." wrote in message
news:F2716F8F1A6DF92ED16212168E98FCB4@in.WebX.maYIadrTaRb...
> Some time back I had a lisp routine that when you picked a single piece of
> text, even a sentence, it would draw a box (polyline) around the text.
>
> Anyone have one of those that they'd like to share?
>
> Thanks-
>
Message 10 of 22
Anonymous
in reply to: Anonymous

Chip gave you part of the URLs. Here is the rest.

Customer Files is a discussion group for upload of problem files
for review. Please Zip any files prior to uploading to conserve
user download time and server space.

For NNTP newsgroup readers the Customer-files newsgroup can be
found at
news://discussion.autodesk.com/autodesk.autocad.customer-files.

You may also access the customer-files group via the HTTP
web-based forums at
http://discussion.autodesk.com/WebX?14@@.ee940b5.
--
Anne Brown
Manager, Moderator
Autodesk Product Support discussion groups
Discussion Q&A: http://www.autodesk.com/discussion

"Tom C." wrote:
>
> customer files?
> where?
>
Message 11 of 22
Anonymous
in reply to: Anonymous

Hi Tom

Perhaps this helps you:

(defun C:TextBox ( / CurSet CurEnt EntCnt PntLst RecEnt OffDst OffPnt
OldCmd OldUci OldUcf)
(setq CurSet (cond
((ssget "_I" '((0 . "TEXT"))))
(T (ssget '((0 . "TEXT"))))
)
)
(if CurSet
(progn
(setq OldCmd (getvar "CMDECHO")
OldUci (getvar "UCSICON")
OldUcf (getvar "UCSFOLLOW")
EntCnt 0
)
(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)
EntCnt (1+ EntCnt)
)
(command "_.UCS" "_OBJ" CurEnt)
(setq PntLst (textbox (entget CurEnt))
OffPnt (polar (cadr PntLst) 0 0.001)
OffDst 1.0 ;Distance Text -> Rectangle
)
(command "_.RECTANGLE" (car PntLst) (cadr PntLst))
(setq RecEnt (entlast))
(command "_.OFFSET" OffDst RecEnt OffPnt ""
"_.ERASE" RecEnt ""
"_.UCS" "_PRE"
)
)
(setvar "UCSICON" OldUci)
(setvar "UCSFOLLOW" OldUcf)
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_.UNDO" "_END")
)
(setvar "CMDECHO" OldCmd)
)
)
(princ)
)

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch

"Tom C." schrieb:
>
> Some time back I had a lisp routine that when you picked a single piece of
> text, even a sentence, it would draw a box (polyline) around the text.
>
> Anyone have one of those that they'd like to share?
>
> Thanks-
Message 12 of 22
Anonymous
in reply to: Anonymous

Thanks, Chip:)
Message 13 of 22
HS20EXR
in reply to: Anonymous

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.

Message 14 of 22
pbejse
in reply to: HS20EXR

An alternative:

 

If you have Express Tools

command: Tcircle

 

 

Message 15 of 22
Kent1Cooper
in reply to: HS20EXR


@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.

Kent Cooper, AIA
Message 16 of 22
HS20EXR
in reply to: pbejse


@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. 

Message 17 of 22
HS20EXR
in reply to: Kent1Cooper

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.

Message 18 of 22
pbejse
in reply to: HS20EXR


@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

Message 19 of 22
HS20EXR
in reply to: pbejse

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? 

Message 20 of 22
HS20EXR
in reply to: Kent1Cooper

 Jurg Menzi's routine modification has the advantages you mentioned, unfortunately has one big drawback, works for TEXT only, not for MTEXT. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost