Hi Friends, in this article I will explain about how to get midpoint between two points in AutoCAD or AutoLISP.

- In AutoCAD we can easily get the midpoint of the line because if you select on the line then three points will select, the middle point is the midpoint of the line .
- But if we get the midpoint of the line in AutoLISP it may difficult. For this I will give you the easiest way to get midpoint between two points in AutoLISP.
- The below figure shows the line draw in AutoCAD if we select the line how it will show the midpoint.

- Open AutoLISP Editor Copy and Paste or write the below code to get the midpoint of line.

(defun c:mid() (setq p1(getpoint "\n Pick First Point of the line") p2(getpoint "\n Pick Second Point of the line") p3(getpoint "\n Pick Second Point of the line") ) (command "line" p1 p2 "") (setq x(/ (- (car p2) (car p1)) 2.00)) (setq y(/ (- (cadr p2) (cadr p1)) 2.00)) (setq midpoint(list (+ (car p1) x) (+ (cadr p1) y))) (command "line" p3 midpoint "") ) |

- In the above code
**car**means the first coordinate of the pick point. i.e. if we select point in AutoCAD it will give coordinates as (1023.6 -1886.05 0.0).So (car p1) means 1023.6. And (cadr p1) means -1886.05.if you want z-coordinate take (caddr p1) it will give 0.0. - Save the code as
**mid.lsp.**Open AutoCAD and type the below commands.

Command: (load "mid")C:MIDCommand: mid Pick First Point of the line Pick Second Point of the line Pick Second Point of the line |

- The output will below if you select p1 and p2 points in horizontally.

## No comments:

## Post a Comment