+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Oct 2017
    Posts
    6

    Default Insert a point at each vertex of selected 2D or 3D polyline!

    Registered forum members do not see this ad.

    Hei,

    Gould anyone help me to make autolisp like this? I want add points automatically to 2d or 3d polyline vertex! I have autolisp that can draw circles but not points!

    Best regards!
    Margus

    test.lsp

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,058

    Default

    Code:
    (defun C:test ( / L )
      (and 
        (setq L (car (entsel "\nPick Polyline: ")))
        (setq L (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget L)))
        (mapcar '(lambda (x) (entmakex (list '(0 . "POINT") x))) L)
      ); and
      (princ)
    ); defun
    (vl-load-com)(princ)

  3. #3
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Oct 2017
    Posts
    6

    Default

    Thanks Grrr,

    Its not working in acad 2018!

    Margus

  4. #4
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,058

    Default

    Try again (I've forgot to entget) <duh>, btw this should be faster:

    Code:
    (defun C:test ( / L )
      (if (setq L (car (entsel "\nSelect polyline: ")))
        (foreach x (entget L)
          (if (= 10 (car x))
            (entmakex (list '(0 . "POINT") x))
          )
        )
      )
      (princ)
    ); defun

  5. #5
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Oct 2017
    Posts
    6

    Default

    Thanks!

    Now it´s working on 2d polyline! Is it possible make working 3d polyline too?

    Margus

  6. #6
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Oct 2017
    Posts
    6

    Default

    Multiple polyline selection is too great success!

  7. #7
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,058

    Default

    Yeah - I've forgot that there were "VERTEX" entities (since I work only in 2D):

    Code:
    ; entmakes points on vertices of lines/polylines
    (defun C:test ( / foo SS i )
      
      (defun foo ( e / enx typ )
        (setq enx (entget e)) (setq typ (cdr (assoc 0 enx)))
        (cond 
          ( (= "LINE" typ)
            (entmakex (list '(0 . "POINT") (assoc 10 enx)))
            (entmakex (list '(0 . "POINT") (cons 10 (cdr (assoc 11 enx)))))
          )
          ( (= "LWPOLYLINE" typ)
            (foreach x enx
              (if (= 10 (car x))
                (entmakex (list '(0 . "POINT") x))
              )
            )
          )
          ( (= "POLYLINE" typ)
            (while (and (setq e (entnext e)) (= "VERTEX" (cdr (assoc 0 (setq enx (entget e))))))
              (entmakex (list '(0 . "POINT") (assoc 10 enx)))
            )
          )
        ); cond
      ); defun foo
      
      (if (setq SS (ssget '((0 . "*LINE"))))
        (repeat (setq i (sslength SS))
          (foo (ssname SS (setq i (1- i))))
        )
      )
      (princ)
    ); defun C:test

  8. #8
    Senior Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    431

    Default

    Code:
    (defun c:foo (/ _point c el p s typ)
      ;; Code updated to account for 2d & 3d lists & lines
      (defun _point (p) (entmakex (list '(0 . "POINT") '(8 . "POINT") (cons 10 p))))
      (if (and (setq s (ssget '((0 . "*polyline,line")))))
        (foreach pl	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
          (cond ((= "LINE" (setq typ (cdr (assoc 0 (setq el (entget pl))))))
    	     (_point (cdr (assoc 10 el)))
    	     (_point (cdr (assoc 11 el)))
    	    )
    	    ((setq p (vlax-get (vlax-ename->vla-object pl) 'coordinates))
    	     (setq c (= "LWPOLYLINE" typ))
    	     (while p
    	       (_point (if c
    			 (list (car p) (cadr p))
    			 (list (car p) (cadr p) (caddr p))
    		       )
    	       )
    	       (if c
    		 (setq p (cddr p))
    		 (setq p (cdddr p))
    	       )
    	     )
    	    )
          )
        )
      )
      (princ)
    )
    (vl-load-com)
    Last edited by ronjonp; 10th Oct 2017 at 01:49 pm.

  9. #9
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,058

    Default

    Nice one Ron,
    I thought about the 'Coordinates approach aswell, but my next thought was that the list would require "group by 3" processing - after seeing your code now I know that this "grouping" could be avoided.

  10. #10
    Senior Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    431

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Grrr View Post
    Nice one Ron,
    I thought about the 'Coordinates approach aswell, but my next thought was that the list would require "group by 3" processing - after seeing your code now I know that this "grouping" could be avoided.
    Cheers!

Similar Threads

  1. Lisp to insert blocks and draw a table for the polyline vertex
    By symoin in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 31st Jan 2017, 09:32 am
  2. Insert a point at each vertex of selected polys
    By gilsoto13 in forum AutoLISP, Visual LISP & DCL
    Replies: 24
    Last Post: 24th Jun 2015, 05:43 pm
  3. need help with vertex point and radius polyline
    By plecs in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 8th Mar 2015, 10:51 pm
  4. closest vertex to a point an polyline
    By HARRY-PLOTTER in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 30th Jan 2014, 03:51 pm
  5. Polyline Vertex at Every Point in List
    By Lee Mac in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 13th Jan 2009, 02:26 pm

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