Exchange Forum > AutoLISP and Visual LISP
Two points for text insertion
Two points for text insertion

#1

Autobahn
Join Date:
08-05-2008
I have need for a lsp file that I can select two points to find the middle insertion point for middle justified text entity. To explain I have to insert text inside boxes in middle of boxes. Now I have been drawing a line lower left to upper right and then use text command and select middle point of line for my insertion point. After I have to erase line. This is very extra work. Maybe one knows a better autolisp way to do it. If you know how please show me.
Two points for text insertion

#2

gile
Join Date:
11-06-2007
Hi,
 
Here's a quickie
 
Code:
(defun c:midtext ()
  (command "_text" "_j" "_mc" "_m2p" pause pause "" "")
  (princ)
)
Two points for text insertion

#3

Autobahn
Join Date:
08-05-2008
You are most appreciated.
Thank you Sir.
Two points for text insertion

#4

Alumni
Join Date:
08-22-2008
Hello,
This is my 1st post, so excuse me I'm a newbie here.
I found this lsp file on my computer that I downloaded somewhere.
It returns the midpoint between two points.
It might apply here, or maybe to a variation of the subject.
Code:
(defun midpt (p1 p2 / a b)
  (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
)
Two points for text insertion

#5

Flynn
Join Date:
07-24-2007
Alumni,
I think your midpt function would be beneficial for some other routines as well.
Thanks for posting.
Flynn
Two points for text insertion

#6

Russell
Join Date:
07-31-2007
Autobahn,
This one kinda' intrigues me. I've done the same thing you described thousands of times. I worked up this function to make our work a little easier. Since we're talking about adding one text entity mc justified, I decided to include the AutoCAD dialog for Edit Text to make it easier to enter text.
Russell
Code:
(defun c:Tx2Pt (/ P1 P2 Pt TextEntity)
  (princ "\nText centered between two points")
  (if (setq P1 (getpoint "\nSpecify first point: "))
    (if (setq P2 (getpoint " Specify second point: " P1))
      (setq Pt (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
    )
  )
  (if Pt
    (progn
      (if (= (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
        (command "text" "j" "mc" Pt "" "" (chr 160))
        (command "text" "j" "mc" Pt "" (chr 160))
      )
      (setq TextEntity (entlast))
      (command "ddedit" TextEntity "")
      (if (= (cdr (assoc 1 (entget TextEntity))) (chr 160))
        (entdel TextEntity)
      )
    )
  )
  (princ)
)