Draw a line from its midpoint

Draw a line from its midpoint

Anonymous
Not applicable
12,505 Views
14 Replies
Message 1 of 15

Draw a line from its midpoint

Anonymous
Not applicable

Hi, this is kind of hard to explain, but is there a way to draw a line starting at its midpoint? Like if I want to draw a 10 inch line i pick a point and it extends out in both directions 5 inches. Kind of like how you draw a circle. Sorry if this is a stupid question, or if it is super simple or easy to do.

 

Thanks for taking the time to read this, and any help is greatly appreciated.

Accepted solutions (1)
12,506 Views
14 Replies
Replies (14)
Message 2 of 15

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

you might use a block as replacement for a line. The block can contain a line from -1,0 to +1,0 ... when you then insert the block you can show rotation and scalefactor and the result would be a (visual) line which has it's midpoint where you showed the insertion point of the block.

 

I would not know a function that can do that in AutoCAD.

Alterative could be to use commands _LENGTHEN or _SCALE, but then the line has already to exist.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 15

dbroad
Mentor
Mentor

Use an xline and trim.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 15

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

There is no in-the-box way to do this.  You could construct a dynamic block that inserts at the middle and then allows you to stretch the line. Or, perhaps a visit to the customization forum will get you a lisp routine that does this for you.

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
Message 5 of 15

Kent1Cooper
Consultant
Consultant

If you don't mind not seeing both ends stretch, but you're open to drawing half of it and then having it "finished" to full length [in simplest terms]:

 

(defun C:LineMid ()
  (command
    "_.LINE" pause pause ""
    "_.scale" "_last" "" "@" 2
  ); command
  (princ)
)

Prompts could be added where those pauses are, to make it clear what you're going to get.

 

To see it "drag" at both ends as you draw it, a routine using (grread) and (grdraw) shouldn't be hard to work out.

Kent Cooper, AIA
Message 6 of 15

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... 

To see it "drag" at both ends as you draw it, a routine using (grread) and (grdraw) shouldn't be hard to work out.


 

Such as this quickie:

;;  LineMidPoint.lsp [command name: LMP]
;;  To draw a Line starting from its midpoint, rather than from end
;;    to end as in AutoCAD's LINE command.
;;  Drags shape of resulting Line as cursor is moved.
;;  Kent Cooper, 4 January 2019
(defun C:LMP ; = Line from MidPoint
  (/ mid cur cor1 cor3 delta bulge cor2 cor4 prelist vertices rect)
  (setq mid (getpoint "\nMidpoint of Line: "))
  (prompt "\nOne end of Line: ")
  (while
    (and mid (setq cur (grread T 12 0)))
    (cond
      ((= (car cur) 5); moved cursor - draw vector
        (grdraw
          (cadr cur)
          (polar mid (angle (cadr cur) mid) (distance (cadr cur) mid))
          -1 1 ; contrast color to background, highlight
        ); grdraw
      ); moved-cursor condition
      ((= (car cur) 3); picked point - draw Line, end (while) loop
        (entmake
          (list
            '(0 . "LINE")
            (cons 10 (cadr cur))
            (cons 11 (polar mid (angle (cadr cur) mid) (distance (cadr cur) mid)))
          ); list
        ); entmake
        (setq mid nil); end (while) loop
      ); picked-point condition
    ); cond - grread possibilities
  ); while
  (princ)
); defun - LMP
(prompt "\nType LMP to draw a Line starting at its MidPoint.")

Unfortunately, it doesn't honor Osnap for picking the one endpoint [though it does for the midpoint].

 

Kent Cooper, AIA
Message 7 of 15

CRGDesign
Community Visitor
Community Visitor

Another very basic tool every other CAD software has that AUTOCAD doesnt...

Message 8 of 15

ryanYF2FK
Participant
Participant

I was getting graphical glitches when I tried Kent Cooper's. It may be an issue of what versions we're using.

 

Anyway, I made up my own. Activate with "LMID".

 

Update: I started getting odd errors, and found that there are several situations that break what I made. I'm pulling this down until I can figure out the issue.

0 Likes
Message 9 of 15

Kent1Cooper
Consultant
Consultant

@ryanYF2FK wrote:

I was getting graphical glitches when I tried Kent Cooper's. ....


[Which one?  What kinds of issues?]

Kent Cooper, AIA
0 Likes
Message 10 of 15

ryanYF2FK
Participant
Participant

With LMP, I was getting ghosted images like in this photo. 

ryanYF2FK_0-1739473911382.png

 

The first one you shared (LineMid) seems to work great! I completely missed it when I was reading through the comments originally. Now if I fix mine, it'll only be for the practice haha

0 Likes
Message 11 of 15

pendean
Community Legend
Community Legend

@ryanYF2FK wrote:

With LMP, I was getting ghosted images like in this photo. 


I bet a REGEN or REGENALL command fixes that, doesn't it.

 

Your video card choked, nothing more: share with us screenshots of your AutoCAD's ABOUT and GRAPHICSCONFIG command pop-ups please.

0 Likes
Message 12 of 15

ryanYF2FK
Participant
Participant

I tried both regeneration commands and it didn't fix it. But I still admit it's probably my graphic's card - it's on my work computer, and I've had problems with it ever since they bought it.

 Screenshot 2025-02-13 163917.png

Screenshot 2025-02-13 164924.png

Should I make this into a separate post somewhere? Not trying to spam everyone.

0 Likes
Message 13 of 15

cadffm
Consultant
Consultant
Accepted solution

Hi,
regardless of the problem here:

You have installed "less important" updates for Architecture, but not a single update for AutoCAD?

AutoCAD Productversion, current is 2025.1.1

 

[F1] https://help.autodesk.com/view/ARCHDESK/2025/ENU/?guid=AUTOCAD_2025_UPDATES

Sebastian

0 Likes
Message 14 of 15

ryanYF2FK
Participant
Participant

Good catch, thanks. I've got that fixed now.

0 Likes
Message 15 of 15

vladimir_michl
Advisor
Advisor

A useful tool. Extended now with osnaps (LeeMac's), center glyph and fixed-distance option:

 

;;  LineMidPoint.lsp [command name: LMP]
;;  To draw a Line starting from its midpoint, rather than from end
;;    to end as in AutoCAD's LINE command.
;;  Drags shape of resulting Line as cursor is moved.
;;  Kent Cooper, 4 January 2019
;;
;;  Osnaps, Dist, Center glyph - V.Michl, www.cadforum.cz, 4/2026

(defun C:LMP ; = Line from MidPoint
  (/ mid cur cor1 cor3 delta bulge cor2 cor4 prelist vertices rect osf ospt vs mode distf)


;; Object Snap for grread: Snap Function  -  Lee Mac
;; Returns: [fun] A function requiring two arguments:
;; p - [lst] UCS Point to be snapped
;; o - [int] Object Snap bit code
;; The returned function returns either the snapped point (displaying an appropriate snap symbol)
;; or the supplied point if the snap failed for the given Object Snap bit code.

(defun LM:grsnap:snapfunction ( )
    (eval
        (list 'lambda '( p o / q )
            (list 'if '(zerop (logand 16384 o))
                (list 'if
                   '(setq q
                        (cdar
                            (vl-sort
                                (vl-remove-if 'null
                                    (mapcar
                                        (function
                                            (lambda ( a / b )
                                                (if (and (= (car a) (logand (car a) o)) (setq b (osnap p (cdr a))))
                                                    (list (distance p b) b (car a))
                                                )
                                            )
                                        )
                                       '(
                                            (0001 . "_end")
                                            (0002 . "_mid")
                                            (0004 . "_cen")
                                            (0008 . "_nod")
                                            (0016 . "_qua")
                                            (0032 . "_int")
                                            (0064 . "_ins")
                                            (0128 . "_per")
                                            (0256 . "_tan")
                                            (0512 . "_nea")
                                            (2048 . "_app")
                                            (8192 . "_par")
                                        )
                                    )
                                )
                               '(lambda ( a b ) (< (car a) (car b)))
                            )
                        )
                    )
                    (list 'LM:grsnap:displaysnap '(car q)
                        (list 'cdr
                            (list 'assoc '(cadr q)
                                (list 'quote
                                    (LM:grsnap:snapsymbols
                                        (atoi (cond ((getenv "AutoSnapSize")) ("5")))
                                    )
                                )
                            )
                        )
                        (LM:OLE->ACI
                            (if (= 1 (getvar 'cvport))
                                (atoi (cond ((getenv "Layout AutoSnap Color")) ("117761")))
                                (atoi (cond ((getenv  "Model AutoSnap Color")) ("104193")))
                            )
                        )
                    )
                )
            )
           '(cond ((car q)) (p))
        )
    )
)

;; Object Snap for grread: Display Snap  -  Lee Mac
;; pnt - [lst] UCS point at which to display the symbol
;; lst - [lst] grvecs vector list
;; col - [int] ACI colour for displayed symbol
;; Returns nil

(defun LM:grsnap:displaysnap ( pnt lst col / scl )
    (setq scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
          pnt (trans pnt 1 2)
    )
    (grvecs (cons col lst)
        (list
            (list scl 0.0 0.0 (car  pnt))
            (list 0.0 scl 0.0 (cadr pnt))
            (list 0.0 0.0 scl 0.0)
           '(0.0 0.0 0.0 1.0)
        )
    )
)

;; Object Snap for grread: Snap Symbols  -  Lee Mac
;; p - [int] Size of snap symbol in pixels
;; Returns: [lst] List of vector lists describing each Object Snap symbol

(defun LM:grsnap:snapsymbols ( p / -p -q -r a c i l q r )
    (setq -p (- p) q (1+  p)
          -q (- q) r (+ 2 p)
          -r (- r) i (/ pi 6.0)
           a 0.0
    )
    (repeat 12
        (setq l (cons (list (* r (cos a)) (* r (sin a))) l)
              a (- a i)
        )
    )
    (setq c (apply 'append (mapcar 'list (cons (last l) l) l)))
    (list
        (list 1
            (list -p -p) (list p -p) (list p -p) (list p p) (list p p) (list -p p) (list -p p) (list -p -p)
            (list -q -q) (list q -q) (list q -q) (list q q) (list q q) (list -q q) (list -q q) (list -q -q)
        )
        (list 2
            (list -r -q) (list 0  r) (list 0  r) (list r -q)
            (list -p -p) (list p -p) (list p -p) (list 0  p) (list 0  p) (list -p -p)
            (list -q -q) (list q -q) (list q -q) (list 0  q) (list 0  q) (list -q -q)
        )
        (cons 4 c)
        (vl-list* 8 (list -r -r) (list r r) (list r -r) (list -r r) c)
        (list 16
            (list p 0) (list 0 p) (list 0 p) (list -p 0) (list -p 0) (list 0 -p) (list 0 -p) (list p 0)
            (list q 0) (list 0 q) (list 0 q) (list -q 0) (list -q 0) (list 0 -q) (list 0 -q) (list q 0)
            (list r 0) (list 0 r) (list 0 r) (list -r 0) (list -r 0) (list 0 -r) (list 0 -r) (list r 0)
        )
        (list 32
            (list  r r) (list -r -r) (list  r q) (list -q -r) (list  q r) (list -r -q)
            (list -r r) (list  r -r) (list -q r) (list  r -q) (list -r q) (list  q -r)
        )
        (list 64
            '( 0  1) (list  0  p) (list  0  p) (list -p  p) (list -p  p) (list -p -1) (list -p -1) '( 0 -1)
            '( 0 -1) (list  0 -p) (list  0 -p) (list  p -p) (list  p -p) (list  p  1) (list  p  1) '( 0  1)
            '( 1  2) (list  1  q) (list  1  q) (list -q  q) (list -q  q) (list -q -2) (list -q -2) '(-1 -2)
            '(-1 -2) (list -1 -q) (list -1 -q) (list  q -q) (list  q -q) (list  q  2) (list  q  2) '( 1  2)
        )
        (list 128
            (list (1+ -p) 0) '(0 0) '(0 0) (list 0 (1+ -p))
            (list (1+ -p) 1) '(1 1) '(1 1) (list 1 (1+ -p))
            (list -p q) (list -p -p) (list -p -p) (list q -p)
            (list -q q) (list -q -q) (list -q -q) (list q -q)
        )
        (vl-list* 256 (list -r r)  (list r r) (list -r (1+ r)) (list r (1+ r)) c)
        (list 512
            (list -p -p) (list  p -p) (list -p  p) (list p p) (list -q -q) (list  q -q)
            (list  q -q) (list -q  q) (list -q  q) (list q q) (list  q  q) (list -q -q)
        )
        (list 2048
            (list   -p     -p) (list    p      p) (list   -p      p) (list    p     -p)
            (list (+ p 05) -p) (list (+ p 06) -p) (list (+ p 05) -q) (list (+ p 06) -q)
            (list (+ p 09) -p) (list (+ p 10) -p) (list (+ p 09) -q) (list (+ p 10) -q)
            (list (+ p 13) -p) (list (+ p 14) -p) (list (+ p 13) -q) (list (+ p 14) -q)
            (list -p -p) (list p -p) (list p -p) (list p p) (list p p) (list -p p) (list -p p) (list -p -p)
            (list -q -q) (list q -q) (list q -q) (list q q) (list q q) (list -q q) (list -q q) (list -q -q)
        )
        (list 8192 (list r 1) (list -r -q) (list r 0) (list -r -r) (list r q) (list -r -1) (list r r) (list -r 0))
    )
)

;; Object Snap for grread: Parse Point  -  Lee Mac
;; bpt - [lst] Basepoint for relative point input, e.g. @5,5
;; str - [str] String representing point input
;; Returns: [lst] Point represented by the given string, else nil

(defun LM:grsnap:parsepoint ( bpt str / str->lst lst )
 
    (defun str->lst ( str / pos )
        (if (setq pos (vl-string-position 44 str))
            (cons (substr str 1 pos) (str->lst (substr str (+ pos 2))))
            (list str)
        )
    )

    (if (wcmatch str "`@*")
        (setq str (substr str 2))
        (setq bpt '(0.0 0.0 0.0))
    )           

    (if
        (and
            (setq lst (mapcar 'distof (str->lst str)))
            (vl-every 'numberp lst)
            (< 1 (length lst) 4)
        )
        (mapcar '+ bpt lst)
    )
)

;; Object Snap for grread: Snap Mode  -  Lee Mac
;; str - [str] Object Snap modifier
;; Returns: [int] Object Snap bit code for the given modifier, else nil

(defun LM:grsnap:snapmode ( str )
    (vl-some
        (function
            (lambda ( x )
                (if (wcmatch (car x) (strcat (strcase str t) "*"))
                    (progn
                        (princ (cadr x)) (caddr x)
                    )
                )
            )
        )
       '(
            ("endpoint"      " of " 00001)
            ("midpoint"      " of " 00002)
            ("center"        " of " 00004)
            ("node"          " of " 00008)
            ("quadrant"      " of " 00016)
            ("intersection"  " of " 00032)
            ("insert"        " of " 00064)
            ("perpendicular" " to " 00128)
            ("tangent"       " to " 00256)
            ("nearest"       " to " 00512)
            ("appint"        " of " 02048)
            ("parallel"      " to " 08192)
            ("none"          ""     16384)
        )
    )
)

;; OLE -> ACI  -  Lee Mac
;; Args: c - [int] OLE Colour

(defun LM:OLE->ACI ( c )
    (apply 'LM:RGB->ACI (LM:OLE->RGB c))
)

;; OLE -> RGB  -  Lee Mac
;; Args: c - [int] OLE Colour

(defun LM:OLE->RGB ( c )
    (mapcar '(lambda ( x ) (lsh (lsh (fix c) x) -24)) '(24 16 8))
)

;; RGB -> ACI  -  Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values

(defun LM:RGB->ACI ( r g b / c o )
    (if (setq o (vla-getinterfaceobject (LM:acapp) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
        (progn
            (setq c (vl-catch-all-apply '(lambda ( ) (vla-setrgb o r g b) (vla-get-colorindex o))))
            (vlax-release-object o)
            (if (vl-catch-all-error-p c)
                (prompt (strcat "\nError: " (vl-catch-all-error-message c)))
                c
            )
        )
    )
)

;; Application Object  -  Lee Mac
;; Returns the VLA Application Object

(defun LM:acapp nil
    (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
    (LM:acapp)
)

;---------------------------------------------------------------------------------------------------

  (setq mid (getpoint "\nMidpoint of Line: "))
  (prompt "\nOne end of Line [Distance/Float]: ")
  (setq osf (LM:grsnap:snapfunction)) ; osnap
  (setq mode "F")
  (while
    (and mid (setq cur (grread T 12 0))) ; was 12, 13?
    (setq vs (/ (getvar "VIEWSIZE") 100.0))
    (redraw)

  (grvecs (list 1
				(polar mid 0 vs) (polar mid 1.57 vs)
				(polar mid 1.57 vs) (polar mid 3.14 vs)
				(polar mid 3.14 vs) (polar mid 4.71 vs)
				(polar mid 4.71 vs) (polar mid 6.28 vs)
           ))

    (cond
      ((= (car cur) 5); moved cursor - draw vector
	   (if (= mode "F")
	    (setq ospt (osf (cadr cur) (getvar "OSMODE")))
	    (setq ospt (polar mid (angle (cadr cur) mid) distf))
	   )
        (grdraw
          ospt ; (cadr cur)
		 (if (= mode "F")
           (polar mid (angle ospt mid) (distance ospt mid))
		  (polar mid (angle mid (cadr cur)) distf)
		 )
          -1 1 ; contrast color to background, highlight 1
        ); grdraw
      ); moved-cursor condition

      ((= (car cur) 3); picked point - draw Line, end (while) loop
	   (if (= mode "F")
	    (setq ospt (osf (cadr cur) (getvar "OSMODE")))
	    (setq ospt (polar mid (angle (cadr cur) mid) distf))
	   )
        (entmake
          (list
            '(0 . "LINE")
            (cons 10 ospt)
	       (if (= mode "F")
             (cons 11 (polar mid (angle ospt mid) (distance ospt mid)))
             (cons 11 (polar mid (angle mid (cadr cur)) distf))
	       )
          ); list
        ); entmake
        (setq mid nil); end (while) loop
      ); picked-point condition

	  ((= (car cur) 2)
	    (if (member (chr (cadr cur)) '("d" "D")) (progn (setq mode "D") (setq distf (getdist " Fixed distance: "))))
	    (if (member (chr (cadr cur)) '("f" "F")) (setq mode "F"))
	  )
	  ;(T (princ cur)) ; else
    ); cond - grread possibilities
  ); while
  (redraw)
  (princ)
); defun - LMP
(prompt "\nType LMP to draw a Line starting at its MidPoint. ")

 

Vladimir Michl, www.arkance.world - www.cadforum.cz 

0 Likes