Jump to content

Drawing circles to all vertices of polyline


Lucas Lim

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 5 years later...
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?

Link to comment
Share on other sites

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