Jump to content
Lucas Lim

Drawing circles to all vertices of polyline

Recommended Posts

Lucas Lim

Does anyone knows whether there are any codes where i can add circles to the all the vertices of polylines automatically?

polylines.jpg

Share this post


Link to post
Share on other sites
fixo

See if that helps

(defun C:PCIRC (/  coords ent rad)
 (setq rad (getreal"\nEnter radius: "))
           (while (setq ent (entsel "\nSelect polyline (or press Enter to Exit) >> "))
           (setq ent (car ent))
      (setq coords (vl-remove-if 'not
      (mapcar
        (function (lambda(p)
      (if (= 10 (car p))(cdr p))))
        (entget ent))))
      
      (foreach pt coords
 (command "_circle" "_non" pt rad)   
   )
         )
           (princ)
 )

Share this post


Link to post
Share on other sites
Lucas Lim

thx for the reply fixo.

 

FYI i just started to learn and use lisp.do u know where i can download the complete lisp for this problem?

Share this post


Link to post
Share on other sites
Tharwat
thx for the reply fixo.

 

FYI i just started to learn and use lisp.do u know where i can download the complete lisp for this problem?

 

Could you please tell where the problem is ?

 

Tharwat

Share this post


Link to post
Share on other sites
Lucas Lim

sorry i am just being a bit blur.the codes does work well.

 

just another question.is there a way to select multiple polylines?

Share this post


Link to post
Share on other sites
Tharwat

YES of course .

 

(setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))

 

But you have to add more functions to the above, if you have intents to replace it with fixo routine.

Share this post


Link to post
Share on other sites
Lucas Lim

may i know wat function should i add as i hv hundreds of polylines to be selected.it would be faster if i could select all the polylines at a time

Share this post


Link to post
Share on other sites
irneb

Well, fixo's routine uses entsel (Entity Select - which only asks for one single entity). What tharwat's suggesting is using the ssget (Selection Set Get). However, this gives something other than an entity reference. What I'd suggest is replacing the entsel with a ssget, but also move it outside the while loop (you only want to select the PLs once in one go don't you?). Then you need to obtain the number of selected entities, use sslength for this. Then you need to loop through the selection set (incrementing an index variable from 0 up to -1 sslength, or do it the other way round if you don't mind the order of the circles). From there you use ssname to obtain the entity reference of the nth item in the selection set. From there on it should be nearly the same.

Share this post


Link to post
Share on other sites
Tharwat

irneb Absolutely right.

 

And here is a start for your routine Lucas Lim .

 

(if (setq ss1 (ssget ":L" '((0 . "POLYLINE,LWPOLYLINE"))))
   (progn
     (setq i -1
    ss1 (sslength ss1)
    )
      (while (setq e (ssname ss1 (setq i (1+ i))))
	(...................
                
   (princ)
  ) 
 

 

Tharwat

Share this post


Link to post
Share on other sites
fixo
thx for the reply fixo.

 

FYI i just started to learn and use lisp.do u know where i can download the complete lisp for this problem?

 

this is a great net resource:

 

http://www.afralisp.net/

 

FYI, I had started to learn lisp from there :)

 

Thanks to Kenny Ramage The Great

 

~'J'~

Share this post


Link to post
Share on other sites
alanjt

I did this the other day...

 

(defun c:COV (/ foo ss)
 ;; Circles On Vertices (create circle on vertices of selected Arcs, Lines, *Polylines, Splines)
 ;; Alan J. Thompson, 09.09.10 / 09.22.10

 (defun foo (p)
   (if (vl-consp p)
     (or (vl-member-if
           (function (lambda (a) (equal (list (car a) (cadr a)) (list (car p) (cadr p)))))
           plst
         )
         (setq plst (cons (cdr
                            (assoc 10
                                   (entmake (list '(0 . "CIRCLE") (cons 10 p) (cons 40 *COV:RAD*)))
                            )
                          )
                          pLst
                    )
         )
     )
   )
 )

 (if (and (setq ss (ssget '((0 . "ARC,LINE,*POLYLINE,SPLINE"))))
          (not (initget 6))
          (setq *COV:RAD* (cond ((getdist (strcat "\nSpecify circle radius"
                                                  (if *COV:RAD*
                                                    (strcat " <" (rtos *COV:RAD*) ">: ")
                                                    ": "
                                                  )
                                          )
                                 )
                                )
                                (*COV:RAD*)
                          )
          )
     )
   ((lambda (i / e eLst p pLst)
      (while (setq e (ssname ss (setq i (1+ i))))
        (cond
          ((vl-position (cdr (assoc 0 (setq eLst (entget e)))) '("ARC" "LINE" "SPLINE"))
           (mapcar (function foo) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)))
          )
          ((vl-position (cdr (assoc 0 eLst)) '("LWPOLYLINE" "POLYLINE"))
           (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
             (foo (vlax-curve-getPointAtParam e (setq p (1- p))))
           )
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Edited by alanjt

Share this post


Link to post
Share on other sites
afrazawan

please help me how i ll use this code in auto cad pls how can i insert this code in cad

Share this post


Link to post
Share on other sites
irneb

"Simple" way copy-n-paste the code to ACad's command line. "Better" way, save code into a LSP file - then drag-n-drop onto ACad. More "official" way, use AppLoad, browse to LSP file & click Load. "Quicker" and more customizable way, save file to one of the folders in Options --> Files --> Support Paths, type (load "Filename") at the AC command line (including the parentheses and change filename to that which you gave the LSP file). This you need to do for each DWG you've got open, since it will only load it for the current drawing.

 

You could use the (vl-load-all "Filename") to load it for the entire ACad session. Or otherwise there are numerous ways of getting it to load "automatically".

Share this post


Link to post
Share on other sites
alanjt

Above code updated; thought of an easier way to retrieve vertices for LWPolylines and Polylines.

Share this post


Link to post
Share on other sites
udomsak
I did this the other day...

 

(defun c:COV (/ foo ss)
 ;; Circles On Vertices (create circle on vertices of selected Arcs, Lines, *Polylines, Splines)
 ;; Alan J. Thompson, 09.09.10 / 09.22.10

 (defun foo (p)
   (if (vl-consp p)
     (or (vl-member-if
           (function (lambda (a) (equal (list (car a) (cadr a)) (list (car p) (cadr p)))))
           plst
         )
         (setq plst (cons (cdr
                            (assoc 10
                                   (entmake (list '(0 . "CIRCLE") (cons 10 p) (cons 40 *COV:RAD*)))
                            )
                          )
                          pLst
                    )
         )
     )
   )
 )

 (if (and (setq ss (ssget '((0 . "ARC,LINE,*POLYLINE,SPLINE"))))
          (not (initget 6))
          (setq *COV:RAD* (cond ((getdist (strcat "\nSpecify circle radius"
                                                  (if *COV:RAD*
                                                    (strcat " <" (rtos *COV:RAD*) ">: ")
                                                    ": "
                                                  )
                                          )
                                 )
                                )
                                (*COV:RAD*)
                          )
          )
     )
   ((lambda (i / e eLst p pLst)
      (while (setq e (ssname ss (setq i (1+ i))))
        (cond
          ((vl-position (cdr (assoc 0 (setq eLst (entget e)))) '("ARC" "LINE" "SPLINE"))
           (mapcar (function foo) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)))
          )
          ((vl-position (cdr (assoc 0 eLst)) '("LWPOLYLINE" "POLYLINE"))
           (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
             (foo (vlax-curve-getPointAtParam e (setq p (1- p))))
           )
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

 

Hi brp

If I want to change the circle to point How to?

Share this post


Link to post
Share on other sites
Tharwat
Hi brp

If I want to change the circle to point How to?

 

Hi,

 

Alan has not posted in CADTutor for a quite long time and personally I hope he would resume participating in this forum again as before.

Anyway try the following modification and let me know:

 

(defun c:POV (/ foo ss)
 ;; Points On Vertices (create points on vertices of selected Arcs, Lines, *Polylines, Splines)
 ;; Alan J. Thompson, 09.09.10 / 09.22.10
 ;; Modified by Tharwat - Date: 18.May.16

 (defun foo (p)
   (if (vl-consp p)
     (or (vl-member-if
           (function (lambda (a) (equal (list (car a) (cadr a)) (list (car p) (cadr p)))))
           plst
         )
         (setq plst (cons (cdr
                            (assoc 10
                                   (entmake (list '(0 . "POINT") (cons 10 p)))
                            )
                          )
                          pLst
                    )
         )
     )
   )
 )
 (if (setq ss (ssget '((0 . "ARC,LINE,*POLYLINE,SPLINE"))))
   ((lambda (i / e eLst p pLst)
      (while (setq e (ssname ss (setq i (1+ i))))
        (cond
          ((vl-position (cdr (assoc 0 (setq eLst (entget e)))) '("ARC" "LINE" "SPLINE"))
           (mapcar (function foo) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)))
          )
          ((vl-position (cdr (assoc 0 eLst)) '("LWPOLYLINE" "POLYLINE"))
           (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
             (foo (vlax-curve-getPointAtParam e (setq p (1- p))))
           )
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

  • Like 1

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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