Author Topic: HELP, I need some help with LISP  (Read 4435 times)

0 Members and 1 Guest are viewing this topic.

CosmicTruth

  • Guest
HELP, I need some help with LISP
« 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?

Gliderider

  • Guest
Re: HELP, I need some help with LISP
« Reply #1 on: March 05, 2009, 08:27:56 AM »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HELP, I need some help with LISP
« Reply #2 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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HELP, I need some help with LISP
« Reply #3 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
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: HELP, I need some help with LISP
« Reply #4 on: March 05, 2009, 11:00:48 AM »

Welcome to theswamp Cosmic! :pissed:
Keep smile...

ronjonp

  • Needs a day job
  • Posts: 7526
Re: HELP, I need some help with LISP
« Reply #5 on: March 05, 2009, 11:11:37 AM »

Welcome to theswamp Cosmic! :pissed:

Does not seem like much of a welcome  :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: HELP, I need some help with LISP
« Reply #6 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)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HELP, I need some help with LISP
« Reply #7 on: March 05, 2009, 12:13:51 PM »
Thanks Ron.
Where were my manors. 8-)

Welcome CosmicTruth to The Swamp.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CosmicTruth

  • Guest
Re: HELP, I need some help with LISP
« Reply #8 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
: )

scottcd

  • Newt
  • Posts: 52
Re: HELP, I need some help with LISP
« Reply #9 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

AutoCAD Dos R9 - 2018 and BricCAD 18.2

ronjonp

  • Needs a day job
  • Posts: 7526
Re: HELP, I need some help with LISP
« Reply #10 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

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CosmicTruth

  • Guest
Re: HELP, I need some help with LISP
« Reply #11 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...



: )

Cosmic

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HELP, I need some help with LISP
« Reply #12 on: March 08, 2009, 11:49:21 PM »
I like it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.