Jump to content

Offset Text in LISP


Dj_T_Rex2002

Recommended Posts

I have this LISP I'm trying to work on

 

 

(Defun C:RS1( / PT1 PT22 Mid P1 P2 Delta)
 (Command "UCS" "OB" Pause "") ;select room text to match UCS origin
 (SetQ
   PT1 (getpoint "\nFirst point of text:")
   PT2 (getpoint "\nSecond point of text:")
   Mid (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.)) pt1 pt2) ;Sets middle of pt1 and pt2
   P1  (getpoint "\nPICK 1st corner of room:")
   P2  (getpoint "\nPICK Opposite corner of room:")
   Delta (mapcar '- P1 P2)
 ); end of SetQ
 (Command
   "_.MText" "_None" Mid "Style" "Brochure" "J" "TC" "H" "10" "R" "0" "_None" Mid ;insertion of room size text 
   
   (Strcat (Rtos (ABS (Car Delta)) 4 1) " x " (Rtos (ABS (Cadr Delta)) 4 1) ) ;Content or room size
 ""); end of Command
 (command "UCS" "p") ;sets previous UCS origin
); end of Defun

and I have been trying to find information on how to offset the inserted text from the Room Name. It keeps inserting it right below the text but I need it to be 2" below the Room Name ... also if there is a shortcut of selecting the text to set both UCS Origins and Middle of Text rather than using the "Select direction of UCS" then "Pick middle of text by selecting both points" ... I am trying really hard to learn LISP language and this is what I have so far ... also ... where can I load useful LISPs people might need? Have a few that are pretty cool if anyone needs them thanks to CADTutor people over the years :)

Link to comment
Share on other sites

... also if there is a shortcut of selecting the text to set both UCS Origins and Middle of Text rather than using the "Select direction of UCS" then "Pick middle of text by selecting both points" ...

 

i'd prefer ENTMAKE

 

(defun C:RS2 (/  P1 P2 Delta Mid [color="red"]str[/color] )

 (Command "UCS" "OB" Pause "") ;select room text to match UCS origin
 ([color="blue"]if [/color]([color="blue"]and[/color] (setq p1 (getpoint "\npick 1st corner of room:"))
   (setq p2 (getpoint p1 "\npick opposite corner of room:"))
  )[color="#006400"];and[/color]
 ([color="blue"]progn[/color]
   (setq delta (mapcar '- p1 p2)
         mid   (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.))
		([color="blue"]trans [/color]p1 1 0)
		([color="blue"]trans[/color] p2 1 0)) ;sets middle of pt1 and pt2
  [color="red"]str[/color]   (strcat [color="#8b0000"]"ROOM#"[/color][color="#006400"] ;assumed room number[/color] 
        [color="red"]"\\P"[/color] [color="#006400"];next line[/color]
        (rtos (abs (car delta)) 4 1)" x "(rtos (abs (cadr delta)) 4 1))
   )
   
[url="http://exchange.autodesk.com/autocadarchitecture/enu/online-help/ARCHDESK/2012/ENU/pages/WS1a9193826455f5ff18cb41610ec0a2e719-79f8.htm"]; <ENTMAKE MTEXT> with dxf index 0 100 100 1 10 40 50 71 72 [/url]
 
     ) [color="#006400"];progn[/color]
) [color="#006400"];if[/color]
 
 (command "_ucs" "p") ;sets previous ucs origin
 (princ)
 )

Link to comment
Share on other sites

Actually it's just room size ... we do it like this:

 

 

DINING ROOM

14'-0" X 12'-0"

 

 

will the above work if I take out Room#?

Link to comment
Share on other sites

Actually it's just room size ... we do it like this:

 

 

DINING ROOM

14'-0" X 12'-0"

 

will the above work if I take out Room#?

yes, it was just an example you can replace any string..

try this "{\\LDINING ROOM}"

 

good luck!

Link to comment
Share on other sites

It didn't insert the room size. It just said "Current ucs name: *NO NAME*"

 

perhaps you didn't put your code under the comment

; with dxf index 0 100 100 1 10 40 50 71 72

the reason was hoping you can try coding yourself , so how is your progress?

 

your pic shows underlined room number, i assume is MTEXT?

my $0.02 its easier appending the LxW text to the existing room text

as the offset result like this

 

(defun C:RS2 (/ P1 P2 Delta Mid LxW en ls mt room str tx )
 (command "UCS" "OB" "\\") ;select room text to match UCS origin
 (if (and 
   (setq p1 (getpoint "\nPick 1st corner of room: "))
   (setq p2 (getpoint p1 "\nPick opposite corner of room: ")) 
   (setq en (car (entsel "\nPick existing room Text. ")))
   (setq tx (assoc 1 (setq ls (entget en))))
   (wcmatch (setq mt(cdr(assoc 0 (setq ls (entget en)))))"MTEXT,TEXT")
   );and
   (progn (setq	delta (mapcar '- p1 p2)
		mid   (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.)) (trans p1 1 0) (trans p2 1 0));sets middle of pt1 and pt2
		LxW   (strcat (rtos (abs (car delta)) 4 1)" x "(rtos (abs (cadr delta)) 4 1))
		room  (cdr tx)
		str   (strcat room "\\P" LxW)
		)
     (if(= mt "MTEXT")
       (entmod (subst (cons 1 str ) tx ls)) 
       (progn
              [color="#006400"];if TEXT then create new[/color]
       (entmakex (list '(0 . "MTEXT")
		       '(100 . "AcDbEntity")
		       '(100 . "AcDbMText")
			(cons 1 (strcat "{\\L" room "}\\P" LxW))
			(cons 10 mid);(cdr(assoc 10 ls))
			(cons 40 (cdr(assoc 40 ls)))
			(cons 50 (- (cdr(assoc 50 ls))(angle '(0. 0. 0.)(getvar 'ucsxdir))))
			(cons 71 5 )
			(cons 72 5 )
		  )
       );entmakex
       (entdel en); Text
       );progn
       );if
     ) ;progn
   ) ;if
       (command "_ucs" "p")
       (princ)
 ) ;defun

 

p/s: why not try Lee's TextAlign ?

Edited by hanhphuc
TextAlign
Link to comment
Share on other sites

Well my knowledge of code writing is very limited. I'm what you could call a beginner lol. Thanks for your help, I will give that a try later on :)

Link to comment
Share on other sites

  • 2 weeks later...

Ok I still need help with this please. I have modified my lisp routine to have an ESC function but it doesn't seem to be working. Also, I need the offset text from insert point. Here is my code...

(Defun C:RS1( / PT1 P1 P2 Delta *error*)
 ;; Handle Cancel routine by presing ESC key
 (defun *error* (errmsg)
   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
     (princ (strcat "\nError: " errmsg)))
   (command "_.undo" "_E"
     "_.undo" 1)
   (display-msg "The operation was cancelled by the user." 1)
   (princ)
 ); end *error*
 
 ; Main routine

 (Command "UCS" "OB" Pause "") ;Select Room Name text to match UCS origin
 (SetQ
   PT1 (Getpoint "\nSelect the Insert point of Room Name text:")
   P1  (Getpoint "\nPICK 1st corner of room:")
   P2  (Getpoint "\nPICK Opposite corner of room:")
   Delta (Mapcar '- P1 P2)
 ) ;End of SetQ
 (Command
   "_.MText" "_None" PT1 "Style" "Brochure" "J" "TC" "H" "10" "R" "0" "_None" PT1 ;insertion of room size text 
   
   (Strcat (Rtos (ABS (Car Delta)) 4 1) " x " (Rtos (ABS (Cadr Delta)) 4 1) ) ;Content or room size
 ""); end of Command
 (command "UCS" "P") ;sets previous UCS origin
(Princ)
) ;End of Defun

Link to comment
Share on other sites

Ok I still need help with this please. I have modified my lisp routine to have an ESC function but it doesn't seem to be working.

 

1. inside *error* (display-msg ...) is this function loaded?

2. wcmatch

 

try this minor tweak

c:RS2

 

1.wcmatch

2.rt = if your pick text as reference ucs, you can retrieve its coordinates without using getpoint, so you only pick the room text once

3.H = text height also used as offset Y insertion point, here i use room text's size as example

4.if, and , progn

5. mbb & offset factor

 

(Defun C:RS2 (/ PT1 P1 P2 Delta *error* H rt  [color="red"]mbb[/color] )

[color="red"]
(defun mbb (en / a b)
(vla-GetBoundingBox (vlax-ename->vla-object en) 'a 'b)
(apply 'mapcar (cons ''((a b)(* (+ a b) 0.5))
(mapcar 'vlax-safearray->list (list a b)))))[/color]

 ;; Handle Cancel routine by presing ESC key
 (defun *error* (errmsg)
   (if
     	(wcmatch (strcase errmsg t) "*cancel*,*exit*,*break*")
   [color="green"];(display-msg "The operation was cancelled by the user." 1) ; [/color]
   (alert "The operation was cancelled by the user.") [color="green"]; as replacement of display-msg [/color]
     (princ (strcat "\nError: " errmsg))
     )
   (command "_.undo" "_E" "_.undo" 1)

   (princ)
   ) ; end *error*


; Main routine
 ([color="blue"]if[/color] ([color="blue"]and[/color] (setq rt (car (entsel "\nPick Room Text.. "))) ;room text
        [color="red"] (cdr (assoc 1 (entget rt)))[/color] [color="#006400"]; skip if not *text[/color]
         (vl-cmdf "UCS" "OB" rt) ;Select Room Name text to match UCS origin
         (setq H (cdr (assoc 40 (entget rt))))
         (setq PT1 [color="red"](trans (mbb rt) 0 1)[/color][color="silver"] ; (trans (cdr (assoc 10 (entget rt))) 0 1) [/color]
         PT1
         (list (car pt1)(-(cadr pt1)
                         (* H  [color="red"]1.25[/color] )[color="green"] ;offet factor, try 1.0, 1.5, 2.0 etc..[/color]
                          )))
         (setq P1 (Getpoint "\nPICK 1st corner of room: "))
         (setq P2 (Getpoint p1 "\nPICK Opposite corner of room: \n"))
         )
   ([color="blue"]progn[/color](Setq Delta (Mapcar '- P1 P2))
                  (command "_.MText" "_None" PT1 "Style" "Standard" "J" "TC" "H" H "R" "0""_None"
                               PT1 ;insertion of room size text 
                               (Strcat (Rtos (ABS (Car Delta)) 4 1) " x " (Rtos (ABS (Cadr Delta)) 4 1));Content or room size
                               ""
                               ) ; end of Command
          (command "UCS" "P") [color="green"] ;sets previous UCS origin[/color]
          )
   )
 (Princ)
 ) ;End of Defun

Edited by hanhphuc
mbb & offset factor
Link to comment
Share on other sites

Hanhphuc you are a genius. I love how it works but it is offsetting to the right side of the text. I would like to know if there is a way to tweak the following:

1. Place text in the middle of the text that contains a room name

2. Make it to where the offset is not to far from the bottom of the room name

3. When I hit ESC it leaves the UCS with xy rotated rather than how it supposed to be

OffsetText.jpg

Link to comment
Share on other sites

Hanhphuc you are a genius. I love how it works but it is offsetting to the right side of the text. I would like to know if there is a way to tweak the following:

1. Place text in the middle of the text that contains a room name

2. Make it to where the offset is not to far from the bottom of the room name

3. When I hit ESC it leaves the UCS with xy rotated rather than how it supposed to be

 

:oops: standing by the shore you just saw a little tadpole, when you dive deeper will discover there are many giant fishes inside the pond :fishing:

 

1. The coordinates are obtained from existing room text BL justified, but your new MTEXT MC justified.

- alternatively we can obtain midpoint by getting text bounding box , regardless any room text justified.

2. apply offset factor

3. not recommended but if you insist, just remove (command "usc" "P")

 

post #9 changes colored in red

Link to comment
Share on other sites

[quote name=hanhphuc;653240

 

1. The coordinates are obtained from existing room text BL justified' date=' but your new MTEXT MC justified.

- alternatively we can obtain midpoint by getting text bounding box , regardless any room text justified.

2. apply offset factor

3. not recommended but if you insist, just remove (command "usc" "P")

 

post #9 changes colored in red

 

 

I liked the quote lol I am trying to dive deeper but I'm a noob at this lol

 

 

1. Have no clue how to do get a midpoint of the text bounding box.

2. Same as 1

3. If I delete USC it will leave the origin with x at 90 degrees when I hit ESC (Cancel the command)

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