PGia Posted 5 hours ago Author Posted 5 hours ago I was wrong. c:CPL of @GP_ is also inconsistent in some cases. CPL.dwg Quote
PGia Posted 5 hours ago Author Posted 5 hours ago 14 minutes ago, PGia said: I was wrong. c:CPL of @GP_ is also inconsistent in some cases. CPL.dwg 48.18 kB · 0 downloads Welcome back to big game hunting! Quote
SLW210 Posted 3 hours ago Posted 3 hours ago 1 hour ago, PGia said: I was wrong. c:CPL of @GP_ is also inconsistent in some cases. CPL.dwg 48.18 kB · 1 download I already stated that in a few posts. All of them fail in certain situations. That's why people are still taking a shot at solving the issue. I have also already mentioned Civil/GIS programs can do this pretty well. QGIS (free/donation) has a plug-in to do this. Quote
dexus Posted 2 hours ago Posted 2 hours ago (edited) Here is my first attempt at this problem. It creates offset lines and checks the intersections. The precision is dictated by the offsetdistance. The lower it is, the longer it takes to make the polyline and the more points it will have. But it will be more accurate. Afterwards I run this function on the resulting polyline to clean it up. ;| ; Center line - dexus ; https://www.cadtutor.net/forum/topic/98778-hybrid-parallel |; (defun c:testcl (/ ent1 lst offset offsetdistance pts r s1 s2 ss start te1 te2) (defun _polyline (pts) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length pts)) (cons 8 (getvar 'clayer)) (cons 70 0) ) (mapcar (function (lambda (x) (cons 10 x))) pts) ) ) ) (defun _side (pline pnt / cpt end target der) ; https://www.theswamp.org/index.php?topic=55685.msg610429#msg610429 (setq cpt (vlax-curve-getClosestPointTo pline pnt) end (vlax-curve-getEndParam pline) target (vlax-curve-getParamAtPoint pline cpt) der (if (and (equal target (fix target) 1e-8) (or (vlax-curve-isClosed pline) (and (not (equal (vlax-curve-getStartParam pline) target 1e-8)) (not (equal end target 1e-8))) ) ) (mapcar '- (polar cpt (angle '(0 0) (vlax-curve-getFirstDeriv pline (rem (+ target 1e-3) end))) 1.0) (polar cpt (angle (vlax-curve-getFirstDeriv pline (rem (+ (- target 1e-3) end) end)) '(0 0)) 1.0) ) (vlax-curve-getFirstDeriv pline target) ) ) (minusp (sin (- (angle cpt pnt) (angle '(0.0 0.0) der)))) ) ;; Intersections - Lee Mac ;; mod - [int] acextendoption enum of intersectwith method (defun LM:intersections ( ob1 ob2 mod / lst rtn ) (if (and (vlax-method-applicable-p ob1 'intersectwith) (vlax-method-applicable-p ob2 'intersectwith) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) ) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst)) ) ) (reverse rtn) ) (defun getLength (ent) (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) ) (if (not (while (cond ((not (setq ss (ssget '((0 . "LWPOLYLINE"))))) (princ "\nNothing selected. Try again...\n") ) ((/= (sslength ss) 2) (princ "\nSelect 2 polylines! Try again...\n") ) ((and (setq ent1 (ssname ss 0)) (setq ent2 (ssname ss 1)) (setq ent1 (vlax-ename->vla-object ent1)) (setq ent2 (vlax-ename->vla-object ent2)) ) nil ; Stop loop ) ) ) ) (progn (setq s1 (_side ent1 (vlax-curve-getStartPoint ent2))) (setq s2 (_side ent2 (vlax-curve-getStartPoint ent1))) (setq maxlen (max (getLength ent1) (getLength ent2))) (setq offset 0.0) (setq offsetdistance (/ maxlen 1024.0)) (while (progn (setq offset (+ offset offsetdistance)) (setq te1 nil) (setq te2 nil) (setq r (cond ( (or ; Make offset (vl-catch-all-error-p (setq te1 (vl-catch-all-apply 'vlax-invoke (list ent1 'Offset (if s1 offset (- offset)))))) (vl-catch-all-error-p (setq te2 (vl-catch-all-apply 'vlax-invoke (list ent2 'Offset (if s2 offset (- offset)))))) ) (princ "\nOffset failed. ") nil ) ((setq lst (LM:intersections (car te1) (car te2) acExtendNone)) (setq len (getLength (car te1))) (setq lst (mapcar (function (lambda (pt) (list (/ (vlax-curve-getDistAtPoint (car te1) pt) len) pt))) lst)) (setq start t) (setq pts (append lst pts)) ) ((> offset maxlen) nil) ((not start) t) (start nil) ) ) (if te1 (mapcar 'vla-delete te1)) (if te2 (mapcar 'vla-delete te2)) r ) ) (if pts (_polyline (mapcar 'cadr (vl-sort pts (function (lambda (a b) (< (car a) (car b))))))) ) ) ) ) Edited 1 hour ago by dexus 1 Quote
GP_ Posted 2 hours ago Posted 2 hours ago (edited) 2 hours ago, PGia said: I was wrong. c:CPL of @GP_ is also inconsistent in some cases. Could you post the dwg? Edited 2 hours ago by GP_ Quote
PGia Posted 2 hours ago Author Posted 2 hours ago 21 minutes ago, GP_ said: Could you post the dwg? I already attached it in one of my two previous posts Quote
GP_ Posted 6 minutes ago Posted 6 minutes ago 2 hours ago, PGia said: I already attached it in one of my two previous posts In the DWG files you posted, I can't find the polylines indicated in the images. I don't think that result was obtained with CPL. I'd like to run a test, so please attach the DWG file with the reference position in the images. Thanks 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.