mhy3sx Posted May 1 Posted May 1 (edited) this works ;;; Centerline between two polylines ;;; version: 3.0 20260501 (defun c:CPL ( / e1 e2 obj1 obj2 len step d p1 p2 mid pts) (vl-load-com) (defun getObj (msg) (car (entsel msg)) ) (defun midpoint (a b) (mapcar '(lambda (x y) (/ (+ x y) 2.0)) a b) ) (if (and (setq e1 (getObj "\nSelect first polyline: ")) (setq e2 (getObj "\nSelect second polyline: ")) ) (progn (setq obj1 (vlax-ename->vla-object e1)) (setq obj2 (vlax-ename->vla-object e2)) (setq len (min (vlax-curve-getDistAtParam obj1 (vlax-curve-getEndParam obj1)) (vlax-curve-getDistAtParam obj2 (vlax-curve-getEndParam obj2)) ) ) ;; sampling resolution (setq step (/ len 50.0)) (setq d 0.0) (setq pts '()) (while (<= d len) (setq p1 (vlax-curve-getPointAtDist obj1 d)) (setq p2 (vlax-curve-getClosestPointTo obj2 p1)) (setq mid (midpoint p1 p2)) (setq pts (cons mid pts)) (setq d (+ d step)) ) ;; draw polyline (command "_pline") (foreach p (reverse pts) (command p) ) (command "") (princ "\nCenterline created.") ) ) (princ) ) Edited May 1 by mhy3sx Quote
Recommended Posts
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.