TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CosmicTruth on March 05, 2009, 08:17:38 AM

Title: HELP, I need some help with LISP
Post by: CosmicTruth on March 05, 2009, 08:17:38 AM
I'm trying to write a routine to draw circles along a polyline at each vertice
I don't understand the foreach conditionals or for that matter I dont understand LISP at all
the code i made so far seems to be putting the right things into the variables but i'm stuck at the meat of the routine to actually draw the circles at each angle point along the polyline...

;;;Circle along polyline routine to make a circle at each polyline vertice sized to (* .04 drawing scale)
(defun c:capl ()
  (setq scmde (getvar "cmdecho"))   ;set scmde to current cmdecho setting
  (setvar "cmdecho" 0)      ;turn off command echo
  (setq str "What is the drawing scale: ")   ;set up the string for scale prompt
  (setq s (getint str))         ;set s to drawing scale
  (setq ds (* s 0.04))         ;make ds=circle radius
  (setq   l (entsel
       "Select a Polyline"
     )
  )               ;ask for pl select

;;;=====HELP=====
;;; I need some code to draw a circle at each polyline vertice
;;; the circle radius should be ds

  (setvar "cmdecho" scmde)      ;reset commandecho var
  (princ)
)


can someone please help me code this?
Title: Re: HELP, I need some help with LISP
Post by: Gliderider on March 05, 2009, 08:27:56 AM
Maybe this will help
http://forums.augi.com/showthread.php?t=39710&highlight=polyline
Title: Re: HELP, I need some help with LISP
Post by: CAB on March 05, 2009, 09:21:16 AM
Not much that hasn't been done here.   :evil:
http://www.theswamp.org/index.php?topic=10187.0
Title: Re: HELP, I need some help with LISP
Post by: CAB on March 05, 2009, 09:41:31 AM
This is a commented version of one of the routines in my link.
Code: [Select]
(defun c:circlepline (/ ent vlst pt)
  (and ; and will stop at any nill
    (setq ent (car (entsel "\nSelect pline to add circles.")))
    (or (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE") ; verify entity type
        (prompt "\nNot a LWpolyline."))
    ;;  get the pline vertex in a list
    (setq vlst (mapcar 'cdr (vl-remove-if-not
                               '(lambda (x) (= 10 (car x))) (entget ent))))
    (foreach pt vlst ; make the circles
      (entmake (list '(0 . "CIRCLE")
                     (cons 8 "0") ; layer, comment out to use current layer
                     (cons 10 pt) ; center pt
                     (cons 40  (getvar "Dimscale")) ; radius of circle
                     ))
    )
  )
  (princ) ; this leaves no message when the routine ends
)
Title: Re: HELP, I need some help with LISP
Post by: Andrea on March 05, 2009, 11:00:48 AM

Welcome to theswamp Cosmic! :pissed:
Title: Re: HELP, I need some help with LISP
Post by: ronjonp on March 05, 2009, 11:11:37 AM

Welcome to theswamp Cosmic! :pissed:

Does not seem like much of a welcome  :?
Title: Re: HELP, I need some help with LISP
Post by: ronjonp on March 05, 2009, 11:12:39 AM
Here's a variant of CAB's code to place circles on vertex when cursor is near them:

Code: [Select]
(defun c:circlepline (/ vtx done ent p pt vlst vs)
  (if (and (setq ent (entsel "\nSelect pline to add circles."))
           (setq vlst (mapcar 'cdr
                              (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (car ent)))
                      )
           )
      )
    (while (and (setq p (grread 5)) (= (car p) 5))
      (princ (strcat "\rPut cursor near vertex to add circle: "))
      (setq pt  (cadr p)
            vs  (* (getvar 'viewsize) 0.005)
            vtx (vl-remove-if-not '(lambda (x)
                                     (and (equal (car x) (car pt) vs) (equal (cadr x) (cadr pt) vs))
                                   )
                                  vlst
                )
      )
      (if (and vtx (not (vl-position vtx done)))
        (progn (setq done (cons vtx done))
               (entmake (list '(0 . "CIRCLE")
                              (cons 8 "0")
                              (cons 10 (car vtx)) ; center pt
                              '(40 . 18.0) ; 18 units radius
                        )
               )
        )
      )
    )
  )
  (princ)
)
(c:circlepline)
Title: Re: HELP, I need some help with LISP
Post by: CAB on March 05, 2009, 12:13:51 PM
Thanks Ron.
Where were my manors. 8-)

Welcome CosmicTruth to The Swamp.
Title: Re: HELP, I need some help with LISP
Post by: CosmicTruth on March 05, 2009, 09:18:40 PM
Thanks for the warm welcomes
and the great codes  : )
its working great, now I need a fun way to trim the circles.

hey i'm going to buy a book, anyone know a good one?

Thanks
: )
Title: Re: HELP, I need some help with LISP
Post by: scottcd on March 06, 2009, 11:43:10 AM
I am not a big fan of trimming the lines.

Consider placing a block with your circle at an elvation of 2 and a wipeout with an elevation of 1 relative to the polyline vertex.

This still gives a visual appearance of the line being broken, but an inquiry on the line will still give the correct distance between verticies.

Just my 2 cents worth.

Welcome to the swamp  :lol:

Cheers

Scott

Title: Re: HELP, I need some help with LISP
Post by: ronjonp on March 06, 2009, 12:01:25 PM
Thanks for the warm welcomes
and the great codes  : )
its working great, now I need a fun way to trim the circles.

hey i'm going to buy a book, anyone know a good one?

Thanks
: )

Take a look here for trimming circles: http://www.theswamp.org/index.php?topic=20164.msg245188#msg245188
Title: Re: HELP, I need some help with LISP
Post by: CosmicTruth on March 08, 2009, 10:40:40 PM
Thanks for the help, I learned alot.

I know its not much but here is a prize for helping me...

(http://www.theswamp.org/screens/Swamp.jpg)

: )

Cosmic
Title: Re: HELP, I need some help with LISP
Post by: CAB on March 08, 2009, 11:49:21 PM
I like it. (http://www.theswamp.org/screens/index.php?dir=cab/&file=av-BigGrin.gif)