+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Junior Member
    Using
    AutoCAD 2002
    Join Date
    May 2008
    Posts
    21

    Default Automating drawing polylines using Points

    Registered forum members do not see this ad.

    Hello Everyone!

    I am using vanilla AutoCad (R14-2012) and was wondering what the best solution would be for this problem (other than manually drawing each outline which I currently do!)

    I am looking to draw polylines along each point creating a polyline outline (perimeter) around the selected points. This in itself is quite difficult to do well(haven't found a great method yet) but there are multiple groups of points that I would like polylines around without selecting each individual group of points (in an ideal world).

    I realize that getting something 100% right is impossible and some manual editing (maybe a lot!) will be required.

    Attached is a sample of the points I usually have to work with.

    Test 05 2013.dwg

    I have done a bit of research and found some close solutions which I will post below.

    1. Draw the polyline by point ID (can't remember author)

    Code:
    (vl-load-com)
     ;;; to make a 3d polyline*******************************************
     (defun c:pol (/ adoc spc ss cnt plst 3dline)
     (setq adoc(vla-get-activedocument(vlax-get-acad-object)))
     (setq spc(vlax-get adoc
     (if (equal (getvar "cvport") 1)
     'PaperSpace
     'ModelSpace
     );_if
     )
     );_setq
     (setq ss (ssget '((0 . "POINT"))));_select only point objects
     (if ss
     (progn
     (setq cnt 0);_loop counter
     (setq plst '());_empty list
       (while (< cnt (sslength ss))
     (setq plst (cons(cdr(assoc 10(entget (ssname ss cnt))))plst));_make point list
     (setq cnt (1+ cnt));_incerase counter
         );_while
     (setq 3dline (vla-add3dpoly ;_make 3d polyline 
           spc
           (vlax-safearray-fill
      (vlax-make-safearray vlax-vbDouble
      (cons 0 (1- (length (apply 'append plst)))))
      (apply 'append plst)))
           );_setq add 3dpoly
     );_progn
     );_if
     (princ)
       );_defun
     ;;; to make a 3d  spline******************************************
     (defun c:spl (/ adoc spc ss cnt plst 3dline stpt ept)
     (setq adoc(vla-get-activedocument(vlax-get-acad-object)))
     (setq spc(vlax-get adoc
     (if (equal (getvar "cvport") 1)
     'PaperSpace
     'ModelSpace
     );_if
     )
     );_setq
     (setq ss (ssget '((0 . "POINT"))))
     (if ss
     (progn
     (setq cnt 0);_loop counter
     (setq plst '());_empty list
       (while (< cnt (sslength ss))
     (setq plst (cons(cdr(assoc 10(entget (ssname ss cnt))))plst))
     (setq cnt (1+ cnt));_incerase counter
         );_while
     (setq stpt (vlax-3d-point '(0.0 0.0 0.0)));_start pt for spline
     (setq ept (vlax-3d-point '(0.0 0.0 0.0)));_end pt for spline
     (setq cline (vla-addspline
           spc
           (vlax-safearray-fill
      (vlax-make-safearray vlax-vbDouble
      (cons 0 (1- (length (apply 'append plst)))))
      (apply 'append plst))
           stpt
           ept
           )
           );_setq add 3d spline
     );_progn
     );_if
     (princ)
       );_defun
    2. Convex Hull (Lee Mac ftw)

    Code:
    ;; Convex Hull  -  Lee Mac
    ;; Implements the Graham Scan Algorithm to return the
    ;; Convex Hull of a list of points.
    (defun LM:ConvexHull ( lst / hul p0 )
        (cond
            (   (< (length lst) 4)
                lst
            )
            (   t
                (setq p0 (car lst))
                (foreach p1 (cdr lst)
                    (if (or (< (cadr p1) (cadr p0))
                            (and (equal (cadr p1) (cadr p0) 1e-8) (< (car p1) (car p0)))
                        )
                        (setq p0 p1)
                    )
                )
                (setq lst
                    (vl-sort lst
                        (function
                            (lambda ( a b / c d )
                                (if (equal (setq c (angle p0 a)) (setq d (angle p0 b)) 1e-8)
                                    (< (distance p0 a) (distance p0 b))
                                    (< c d)
                                )
                            )
                        )
                    )
                )
                (setq hul (list (caddr lst) (cadr lst) (car lst)))
                (foreach pt (cdddr lst)
                    (setq hul (cons pt hul))
                    (while (and (caddr hul) (LM:Clockwise-p (caddr hul) (cadr hul) pt))
                        (setq hul (cons pt (cddr hul)))
                    )
                )
                hul
            )
        )
    )
    ;; Clockwise-p  -  Lee Mac
    ;; Returns T if p1,p2,p3 are clockwise oriented or collinear
     
    (defun LM:Clockwise-p ( p1 p2 p3 )
        (<  (-  (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
                (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
            )
            1e-8
        )
    )
    (defun c:test1 ( / i l s )
        (if (setq s (ssget '((0 . "POINT"))))
            (progn
                (repeat (setq i (sslength s))
                    (setq l (cons (cdr (assoc 10 (entget (ssname s (setq i (1- i)))))) l))
                )
                (setq l (LM:ConvexHull l))
                (entmakex
                    (append
                        (list
                           '(0 . "LWPOLYLINE")
                           '(100 . "AcDbEntity")
                           '(100 . "AcDbPolyline")
                            (cons 90 (length l))
                           '(70 . 1)
                        )
                        (mapcar '(lambda ( x ) (cons 10 x)) l)
                    )
                )
            )
        )
        (princ)
    )
    3. Create surfaces out of points using triangulation and limit the length of triangle then use bounding box to create polyline(hard to do in vanilla AutoCad).

    4. Neat solution shown by Tyke (which I don't have the code for)

    http://www.youtube.com/watch?v=Dccnn3O4VB4

    5. Possibly use multiple Bpoly commands, somehow getting the Bpoly command to recongnize points???

    6. Outsource?

    Anywho, if you guys have any ideas as to (too?) other methods/possible solutions/software programs/ANYTHING that could be of help that would be awesome!

    Thanks again for reading,

    Kablamtron

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,892

    Default

    This sounds like something better done a step earlier by using points codes xyz & description "join like" descriptors this is known as stringing CIV3d etc its built in.
    A man who never made mistakes never made anything

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,365

    Default

    Registered forum members do not see this ad.

    I have a program that will generate an LWPolyline outline for a selection of points in the plane, as demonstrated by the following animation using some examples from your file:

    pointoutline.gif

    As expected for this form of task, the program does not return what would be considered the 'correct' outline for some point arrangements with tight concave sections, however, the algorithm should produce good results for most general cases.

    The program is not freeware however, and you may contact me if you are interested.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. 3d points & 2d polylines
    By dbroada in forum .NET, ObjectARX & VBA
    Replies: 10
    Last Post: 17th Apr 2013, 02:52 pm
  2. Automating Drawing Concentric Circles
    By endofeternity in forum AutoCAD Beginners' Area
    Replies: 9
    Last Post: 17th Jun 2011, 05:48 am
  3. Polylines to points
    By StuboJones in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 5th Mar 2011, 02:50 pm
  4. intersection points between line and a group of polylines
    By motee-z in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 27th Mar 2006, 04:55 pm
  5. automating drawing?
    By hypersoniq in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 31st Oct 2005, 11:59 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts