AutoLISP: Mid-Point of Entire Polyline

Here is a simple and great routine. This routine places a “point” at the mid-point of the polyline. Usually, you can simply snap to the mid-point of a polyline segment. But if you want to simply find the mid-point of the overall length of a polyline, this isn’t such a simple task. That’s where this routine comes in handy. It will place a point at the middle of the polyline. So prior to running this routine, use the DDPTYPE command to set the size and type of point that you would like to use.

Here’s how:

  • MIDPOLY <enter> to start
  • Select the Polyline to place the point at its mid-point.

I found this LISP routine at the following website [click here]. If you do copy the code from the linked website, don’t forget to add (vl-load-com) to the routine in order for it to work.

;; ! ****************************************************************************

;; ! C:MidPoly

;; ! ****************************************************************************

;; ! Function : Determines the mid point of a polyline and draws a point at that

;; ! location

;; ! Author : Rakesh Rao, (C) 2004, Four Dimension Technologies

;; ! Bangalore, India

;; ! Email :

;; ! Web

;; ! Updated : March 11, 2004

;; ! ****************************************************************************

(defun c:MidPoly ( / ent ename entl en oname param len hLen MidPt OS )


(setq ent (entsel "\nSelect polyline:"))

(if ent



ename (car ent)

entl (entget ename)

en (cdr (assoc 0 entl))


(if (member en (list "POLYLINE" "LWPOLYLINE"))



oname (vlax-ename->vla-object ename)

param (vlax-curve-getEndParam oname)

len (vlax-curve-getDistAtParam oname param)

hLen (* 0.5 len)

MidPt (vlax-curve-getPointAtDist oname hLen)


(vlax-release-object oname)

(setq OS (getvar "OSMODE"))

(setvar "OSMODE" 0)

(command "._Point" MidPt)

(princ "\nPoint object created at mid-point:")(princ MidPt)

(setvar "OSMODE" OS)


(princ "\nYou must pick a polyline object only.")





(princ "\nType 'MidPoly' to start.")


About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Polylines. Bookmark the permalink.

7 Responses to AutoLISP: Mid-Point of Entire Polyline

  1. ramu says:

    Hi, This midpoly lisp file was excellent. very useful.
    The problem is i have more than 10,000 polylines. I cannot select each and everyline to convert into points at the mid point of each line. Is there any other lisp file or can you modify this lisp file to select many objects / polylines at a time.
    Request to reply to my e-mail
    Thanks a lot in advance.

    • AutoCAD Tips says:

      Here is a simple routine that might help:

      (defun C:MDIV (/ ss n segs)
      (setq ss (ssget “X”)
      n (1- (sslength ss))
      segs (getint “\Number of segments per object: “)
      (while (>= n 0)
      (command “_.divide” (ssname ss n) segs)
      (setq n (1- n))

      Note that it will select and “divide” everything by placing a Point at its midpoint

      • ramu says:

        Thanks for your prompt reply and providing new lisp file. When i tried to use this lisp the following error is coming.

        Command: MDIV

        Select objects: Specify opposite corner: 16 found

        Select objects: too many arguments

        I have two lines crossing each other at mid point (like + symbol) and i want to insert a point at the mid point or intersection of both the lines. Hope you understood the requirement.
        Waiting for your reply.

        With regards

      • Andre Putilov says:

        That also happens to me. I need exactly the same function as Ramu. Create a point in the middle of multiple lines.

        The second lisp that you provided gives me the same errors:

        Command: MDIV
        Select objects: Specify opposite corner: 198 found
        Select objects:
        ; error: too many arguments

  2. Rummaan says:

    Sir, I need to mark tributary area on a floor plan that takes midpoints from the surrounding edges. Can you please help me how i can draw a line between midpoints that ends up making a square.

  3. rdh288 says:

    Wow. If I could find something that did this for feature lines it would save me so much time…

    • rdh288 says:

      Actually, nevermind. This works how I need it. When I create a bench, the first step is to extract a contour line and slope it with the midpoint being the highest point. I can use this in the time between extracting the polyline from the surface and turning it into a feature line. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s