Jump to content

Centre Line between two Polylines


SteveMouchel

Recommended Posts

Hi guys,

 

I am working on a road scheme and I need to create a centre line between the two edges of the central reserve/median.

 

I have two 3d Polylines of equal lengths and with the same number of vertices.

 

Does anyone know if this is possible in AutoCAD...? I’ve searched for a script but can’t find anything.

 

Any help would be much appreciated and would certainly save me from digitising the entire centre line… this is one section of a 100km scheme.

 

Regards

 

Steve

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    11

  • JHammond

    5

  • SteveMouchel

    3

  • MSasu

    2

Top Posters In This Topic

Posted Images

Just step through each vertex for each polyline and draw polyline at the midpoint of the two coinciding vertices.

 

 

eg. (quickie)

 

BW.gif

Link to comment
Share on other sites

Also may use the "secret" M2P Osnap mode that will allow to locate the middle between two points - available in AutoCAD 2010.

 

Regards,

Link to comment
Share on other sites

Also may use the "secret" M2P Osnap mode that will allow to locate the middle between two points - available in AutoCAD 2010.

 

Regards,

It was around long before 2010. Also can be called with MTP.
Link to comment
Share on other sites

Just step through each vertex for each polyline and draw polyline at the midpoint of the two coinciding vertices.

 

 

eg. (quickie)

 

[ATTACH]21283[/ATTACH]

 

This looks perfect but I can't test it until I'm back in work tomorrow.

 

What command are you using...? Also, does it work using 3d Polylines...?

Link to comment
Share on other sites

This looks perfect but I can't test it until I'm back in work tomorrow.

 

What command are you using...? Also, does it work using 3d Polylines...?

Something I quickly coded out. Yes, it works on LW, 3D and 2D polylines.
Link to comment
Share on other sites

Also may use the "secret" M2P Osnap mode that will allow to locate the middle between two points - available in AutoCAD 2010.

 

Regards,

 

This is great, I never knew it was there. Unfortunately I don't fancy doing this along a line with 25,000 points :(

Link to comment
Share on other sites

  • 1 month later...

I was pretty slammed today and completely forgot about it. However, since I met all my deadlines today, I'll have plenty of time to play tomorrow and I'll post it first thing. :wink:

Link to comment
Share on other sites

  • 3 weeks later...
I was pretty slammed today and completely forgot about it. However, since I met all my deadlines today, I'll have plenty of time to play tomorrow and I'll post it first thing. :wink:

 

Hi Alan,

 

I was drawing my ramp lines again today and thought I would check to see if the lisp routine you made was posted yet. I hate to be a pest, but could you post it when you get a chance? :unsure: Thanks.

Link to comment
Share on other sites

  • 3 weeks later...
Guest balajibth84

Here no lisp attached for Centre Line creation between two Polylines..How can we create with any single command..Any lisp for this????But u r given reply..here lisp is availble...where here its attached???????

Link to comment
Share on other sites

(defun c:LBL (/ foo AT:GetSel _pnts _pline _lwpline _dist e1 e2)
 ;; Draw (LW)Polyline between two selected curves (at midpoint of vertices).
 ;; Alan J. Thompson, 09.29.10

 (vl-load-com)

 (defun foo (e)
   (and (wcmatch (cdr (assoc 0 (entget (car e)))) "LINE,*POLYLINE,SPLINE")
        (not (vlax-curve-isClosed (car e)))
   )
 )

 (defun AT:GetSel (meth msg fnc / ent good)
   ;; meth - selection method (entsel, nentsel, nentselp)
   ;; msg - message to display (nil for default)
   ;; fnc - optional function to apply to selected object
   ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
   ;; Alan J. Thompson, 05.25.10
   (setvar 'errno 0)
   (while (not good)
     (setq ent (meth (cond (msg)
                           ("\nSelect object: ")
                     )
               )
     )
     (cond
       ((vl-consp ent)
        (setq good (cond ((or (not fnc) (fnc ent)) ent)
                         ((prompt "\nInvalid object!"))
                   )
        )
       )
       ((eq (type ent) 'STR) (setq good ent))
       ((setq good (eq 52 (getvar 'errno))) nil)
       ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again.")))
     )
   )
 )

 (defun _pnts (e / p l)
   (if e
     (cond ((wcmatch (cdr (assoc 0 (entget e))) "ARC,LINE,SPLINE")
            (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e))
           )
           ((wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE")
            (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
              (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l))
            )
           )
     )
   )
 )

 (defun _pline (lst)
   (if (and (> (length lst) 1)
            (entmakex '((0 . "POLYLINE") (10 0 0 0)))
            (foreach x lst (entmakex (list '(0 . "VERTEX") (cons 10 x))))
       )
     (cdr (assoc 330 (entget (entmakex '((0 . "SEQEND"))))))
   )
 )

 (defun _lwpline (lst)
   (if (> (length lst) 1)
     (entmakex (append
                 (list '(0 . "LWPOLYLINE")
                       '(100 . "AcDbEntity")
                       '(100 . "AcDbPolyline")
                       (cons 90 (length lst))
                       (cons 70 (* (getvar 'plinegen) 128))
                 )
                 (mapcar (function (lambda (p) (list 10 (car p) (cadr p)))) lst)
               )
     )
   )
 )

 (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))

 (if
   (and
     (setq e1 (_pnts (car (AT:GetSel entsel "\nSelect first open curve: " foo))))
     (setq e2 (_pnts (car (AT:GetSel entsel "\nSelect next open curve: " foo))))
     (not (initget 0 "Lwpolyline Polyline"))
     (setq *LBL:Opt* (cond ((getkword (strcat "\nSpecify line to draw: [Lwpolyline/Polyline] <"
                                              (cond (*LBL:Opt*)
                                                    ((setq *LBL:Opt* "Lwpolyline"))
                                              )
                                              ">: "
                                      )
                            )
                           )
                           (*LBL:Opt*)
                     )
     )
   )
    ((if (eq *LBL:Opt* "Lwpolyline")
       _lwpline
       _pline
     )
      (vl-remove nil
                 (mapcar (function (lambda (a b)
                                     (if (and a b (not (grdraw (trans a 0 1) (trans b 0 1) 1 1)))
                                       (mapcar (function (lambda (a b) (/ (+ a b) 2.))) a b)
                                     )
                                   )
                         )
                         e1
                         (if (< (_dist (car e1) (car e2))
                                (_dist (car e1) (last e2))
                             )
                           e2
                           (reverse e2)
                         )
                 )
      )
    )
 )
 (princ)
)

Edited by alanjt
Link to comment
Share on other sites

Guest balajibth84

Hai alanjt,I am tried this Code in cad 2007..After lbl command its asking Select first open curve:..After i am selecting means this common geeting exit(Nothing reaction).....Can you check it ones??????please

Link to comment
Share on other sites

Hai alanjt,I am tried this Code in cad 2007..After lbl command its asking Select first open curve:..After i am selecting means this common geeting exit(Nothing reaction).....Can you check it ones??????please

 

  1. I don't understand what you are saying.
  2. It works perfectly fine on my end (tested in 08 and 09).
  3. Post an example drawing of what you are trying to select.

Link to comment
Share on other sites

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