Jump to content

Recommended Posts

Posted

not workin in zwcad!!!

Posted (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 by mhy3sx

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...