Jump to content

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


Margusrebase

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Margusrebase

    7

  • ronjonp

    5

  • Grrr

    5

  • Lee Mac

    3

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

Link to comment
Share on other sites

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

 

(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

Link to comment
Share on other sites

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

 

; 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

Link to comment
Share on other sites

(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,circle")))))
   (foreach pl	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
     (cond ((= "CIRCLE" (setq typ (cdr (assoc 0 (setq el (entget pl))))))
     (_point (cdr (assoc 10 el)))
    )
    ((= "LINE" typ) (_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)

Edited by ronjonp
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

(defun c:foo (/ p s)
 (if (and (setq s (ssget '((0 . "*polyline")))))
   (foreach pl    (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
     (setq p (vlax-get (vlax-ename->vla-object pl) 'coordinates))
     (while p
   (entmakex (list '(0 . "POINT") '(8 . "POINT") (cons 10 (list (car p) (cadr p) (caddr p)))))
   (setq p (cdddr p))
     )
   )
 )
 (princ)
)
(vl-load-com)

 

Ron, I think (caddr p) will point to the x-coordinate of the successive vertex for an LWPolyline; also note that (cons 10 (list ... )) is the same as (list 10 ... )

 

Ok, I'll stop my nit-picking now :ouch:

Link to comment
Share on other sites

Here's another way:

(defun c:pvtx ( / e i p s )
   (if (setq s (ssget '((0 . "*polyline"))))
       (repeat (setq i (sslength s))
           (setq e (ssname s (setq i (1- i))))
           (repeat (- (setq p (fix (+ (vlax-curve-getendparam e) 1 1e-8))) (logand 1 (cdr (assoc 70 (entget e)))))
               (entmake (list '(0 . "POINT") (cons 10 (vlax-curve-getpointatparam e (setq p (1- p))))))
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)
 

FWIW, this:

(- (setq p (fix (+ (vlax-curve-getendparam e) 1 1e-8))) (logand 1 (cdr (assoc 70 (entget e)))))
 

Could also be written:

(+ (setq p (fix (+ (vlax-curve-getendparam e) 1 1e-8))) (vlax-get (vlax-ename->vla-object e) 'closed))
 

But the latter will likely be slower due to vlax-ename->vla-object.

Edited by Lee Mac
Link to comment
Share on other sites

Ron, I think (caddr p) will point to the x-coordinate of the successive vertex for an LWPolyline; also note that (cons 10 (list ... )) is the same as (list 10 ... )

 

Ok, I'll stop my nit-picking now :ouch:

 

You are correct sir :) .. did not even think about 2d points being reported on lwpolylines! Good catch!

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