Margusrebase Posted October 9, 2017 Share Posted October 9, 2017 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 9, 2017 Share Posted October 9, 2017 (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) Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 9, 2017 Author Share Posted October 9, 2017 Thanks Grrr, Its not working in acad 2018! Margus Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 9, 2017 Share Posted October 9, 2017 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 Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 9, 2017 Author Share Posted October 9, 2017 Thanks! Now it´s working on 2d polyline! Is it possible make working 3d polyline too? Margus Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 9, 2017 Author Share Posted October 9, 2017 Multiple polyline selection is too great success! Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 9, 2017 Share Posted October 9, 2017 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 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 9, 2017 Share Posted October 9, 2017 (edited) (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 October 18, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 9, 2017 Share Posted October 9, 2017 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 9, 2017 Share Posted October 9, 2017 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! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 9, 2017 Share Posted October 9, 2017 (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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 9, 2017 Share Posted October 9, 2017 (edited) 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 February 13, 2019 by Lee Mac Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 9, 2017 Share Posted October 9, 2017 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 You are correct sir .. did not even think about 2d points being reported on lwpolylines! Good catch! Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 9, 2017 Share Posted October 9, 2017 Woah, nice iteration Lee! I completely forgot that vlax-curve functions exist. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 9, 2017 Share Posted October 9, 2017 Cheers guys Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 10, 2017 Author Share Posted October 10, 2017 Thanks guys, great work! Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 10, 2017 Author Share Posted October 10, 2017 Hi, I found that this autolisp not working on line! Could enyone add this code too into autolisp? Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 10, 2017 Share Posted October 10, 2017 Hi, I found that this autolisp not working on line! Could enyone add this code too into autolisp? Try the code HERE. Quote Link to comment Share on other sites More sharing options...
Margusrebase Posted October 18, 2017 Author Share Posted October 18, 2017 Hi, Can anyone add circle too to the code? Best regards! Margus Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 18, 2017 Share Posted October 18, 2017 As in put a point at the circle's center? If so code updated HERE. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.