Jump to content

Recommended Posts

Posted

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)

Posted

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)
)

Posted

Thank you very much both of you!

 

Second link and Stefan's solution is exactly what was looking for.

Posted

@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.

Posted
@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.

Posted
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?

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...