vanowm Posted July 8, 2016 Posted July 8, 2016 Hello. Is there a routine somewhere that would draw an "average" spline/pline between two splines/plines? Manually I do the following: 1) apply divide command on both (s)plines to divide both into equal number of segments, 2) draw lines between division points 3) draw new (s)pline through the midpoint of these lines. This is a very slow and tidious process and I wonder if there is something automatic already available? This is probably not most efficient way, but it creates the best result when I need make a symmetrical drawing out "crooked" part: mirror it, put them together and draw the "average". Thank you. P.S. I started putting together a route for this, but I'm having hard time get division coordinates in proper order, I've tried use LeeMac's Segment Curve unfortunately it is entity's start point sensitive (on mirrored entity it starts from the wrong end) Quote
marko_ribar Posted July 8, 2016 Posted July 8, 2016 Here are some links : http://www.cadtutor.net/forum/showthread.php?83644-Centerline-between-two-polylines&p=#1 http://www.cadtutor.net/forum/showthread.php?49709-Centre-Line-between-two-Polylines/page2&p=#17 http://www.cadtutor.net/forum/showthread.php?88968-Endless-Centre-Lines/page2&p=#11 http://www.cadtutor.net/forum/showthread.php?88968-Endless-Centre-Lines/page2&p=#14 Regards, HTH. M.R. Quote
Stefan BMR Posted July 8, 2016 Posted July 8, 2016 Try this (defun c:test ( / a1 a2 d1 d2 e1 e2 k l n p1 p2 x1 x2) (defun start_p (e p) (< (vlax-curve-getdistatpoint e (vlax-curve-getclosestpointto e p) ) (/ (vlax-curve-getdistatparam e (vlax-curve-getendparam e) ) 2.0 ) ) ) (defun m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b)) (if (and (setq e1 (entsel "\nSelect the first object: ")) (setq e2 (entsel "\nSelect the second object: ")) (not (eq (car e1) (car e2))) (or (setq n (getint "\nNumber of divisions <10>: ")) (setq n 10) ) ) (progn (setq p1 (trans (cadr e1) 1 0) e1 (car e1) p2 (trans (cadr e2) 1 0) e2 (car e2) a1 (vlax-curve-getdistatparam e1 (vlax-curve-getendparam e1)) x1 (/ a1 n) a2 (vlax-curve-getdistatparam e2 (vlax-curve-getendparam e2)) x2 (/ a2 n) ) (if (start_p e1 p1) (setq d1 0.0) (setq d1 a1 x1 (- x1))) (if (start_p e2 p2) (setq d2 0.0) (setq d2 a2 x2 (- x2))) (repeat (1+ n) (setq l (cons (m2p (vlax-curve-getpointatdist e1 d1) (vlax-curve-getpointatdist e2 d2) ) l ) d1 (min a1 (max 0.0 (+ d1 x1))) d2 (min a2 (max 0.0 (+ d2 x2))) ) ) (initget "Polyline Spline") (setq k (getkword "\nSpecify object type [Polyline/Spline]<Polyline>: ")) (if (eq k "Spline") (entmakex (append (list '(0 . "SPLINE") '(100 . "AcDbEntity") '(100 . "AcDbSpline") '(70 . 40) '(71 . 3) (cons 74 (length l)) '(44 . 1.0e-005) ) (mapcar '(lambda (x) (cons 11 x)) l) ) ) (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(70 . 0) (cons 90 (length l)) ) (mapcar '(lambda (x) (cons 10 x)) l) ) ) ) ) ) (princ) ) Quote
vanowm Posted July 8, 2016 Author Posted July 8, 2016 Thank you very much both of you! Second link and Stefan's solution is exactly what was looking for. Quote
vanowm Posted July 8, 2016 Author Posted July 8, 2016 @Stefan BMRStefan Any ideas why after execution of your code, undo does 2 steps back instead 1? (easy fix with adding (command "undo" "begin")), but I'm curious what could cause this behavior. Quote
Stefan BMR Posted July 9, 2016 Posted July 9, 2016 @Stefan BMRStefan Any ideas why after execution of your code, undo does 2 steps back instead 1? (easy fix with adding (command "undo" "begin")), but I'm curious what could cause this behavior. The lisp include only the functional part. Feel free to add your favorite error trap and the undo mark, of course. You are here from some time now and I think you should know a simple task like this. Quote
vanowm Posted July 9, 2016 Author Posted July 9, 2016 The lisp include only the functional part. Feel free to add your favorite error trap and the undo mark, of course.You are here from some time now and I think you should know a simple task like this. As I said it's an easy fix, but why it does it in the first place? 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.