Author Topic: LISP to draw circle and make block  (Read 3211 times)

0 Members and 1 Guest are viewing this topic.

mhupp

  • Bull Frog
  • Posts: 250
Re: LISP to draw circle and make block
« Reply #15 on: May 26, 2022, 11:08:47 AM »
Was there a way to use diameter as well as another option?

CBR for radius
CBD for diameter

Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------;;
  2. ;; CREATE CIRCLE BLOCKS WITH UNIQE NAME RAD
  3. (defun c:CBR (/ rad pt blkname)
  4.   (setvar 'cmdecho 0)
  5.   (if (and (setq rad (getdist "\nCircle Radius: ")) (setq pt (getpoint "\nPick Center Point of Circle: ")))
  6.     (progn
  7.       (entmake (list '(0 . "CIRCLE") '(8 . "Fulcrum") (cons 10 pt) (cons 40 rad)))
  8.       (setq blkname (strcat "Block-" (menucmd "M=$(edtime, $(getvar,date),YYMODDHHMMSS)")))
  9.       (vl-cmdf "_.Block" blkname "_non" pt (entlast) "")
  10.       (vl-cmdf "_.Insert" blkname "_non" pt 1 1 0)
  11.       (prompt (strcat "\nBlock [" blkname "] Created"))
  12.     )
  13.   )
  14.   (setvar 'cmdecho 1)
  15.   (princ)
  16. )
  17.  
  18. ;;----------------------------------------------------------------------;;
  19. ;; CREATE CIRCLE BLOCKS WITH UNIQE NAME
  20. (defun c:CBD (/ dia pt blkname)
  21.   (setvar 'cmdecho 0)
  22.   (if (and (setq dia (getdist "\nCircle Diameter: ")) (setq pt (getpoint "\nPick Center Point of Circle: ")))
  23.     (progn
  24.       (entmake (list '(0 . "CIRCLE") '(8 . "Fulcrum") (cons 10 pt) (cons 40 (/ dia 2))))
  25.       (setq blkname (strcat "Block-" (menucmd "M=$(edtime, $(getvar,date),YYMODDHHMMSS)")))
  26.       (vl-cmdf "_.Block" blkname "_non" pt (entlast) "")
  27.       (vl-cmdf "_.Insert" blkname "_non" pt 1 1 0)
  28.       (prompt (strcat "\nBlock [" blkname "] Created"))
  29.     )
  30.   )
  31.   (setvar 'cmdecho 1)
  32.   (princ)
  33. )
« Last Edit: May 26, 2022, 12:52:14 PM by mhupp »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: LISP to draw circle and make block
« Reply #16 on: May 26, 2022, 12:09:19 PM »
Was there a way to use diameter as well as another option?

CBR for radius
CBD for diameter

Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------;;
  2. ...
  3.  
  4. ;;----------------------------------------------------------------------;;
  5. ;; CREATE CIRCLE BLOCKS WITH UNIQE NAME DIA
  6. (defun c:CBD (/ rad pt blkname)
  7.   (setvar 'cmdecho 0)
  8.   (if (and (setq rad (/ (getreal "\nCircle Diameter: ") 2)) (setq pt (getpoint "\nPick Center Point of Circle: ")))
  9.     (progn
  10.       (entmake (list '(0 . "CIRCLE") '(8 . "Fulcrum") (cons 10 pt) (cons 40 rad)))
  11.       (setq blkname (strcat "Block-" (menucmd "M=$(edtime, $(getvar,date),YYMODDHHMMSS)")))
  12.       (vl-cmdf "_.Block" blkname "_non" pt (entlast) "")
  13.       (vl-cmdf "_.Insert" blkname "_non" pt 1 1 0)
  14.       (prompt (strcat "\nBlock [" blkname "] Created"))
  15.     )
  16.   )
  17.   (setvar 'cmdecho 1)
  18.   (princ)
  19. )
@mhupp
FWIW, you should check the existence of the number before dividing otherwise it'll throw an error. I also like to use GETDIST for these types of inputs since you can enter a number as well as pick two points :)
Code - Auto/Visual Lisp: [Select]
  1. (and (setq rad (getdist "\nCircle Diameter: "))
  2.      (setq rad (/ rad 2))
  3.      (setq pt (getpoint "\nPick Center Point of Circle: "))
  4. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: LISP to draw circle and make block
« Reply #17 on: May 26, 2022, 12:11:43 PM »
This is finally working, I don't know why it wasn't before as LSP file was saved after changes.

Was there a way to use diameter as well as another option?
What do you use these for? Have you thought about using a circle block ( as mentioned above ) then changing the scale to get the correct size? Then you wouldn't have a bunch of blocks with different names that look the same but only have a different radius.

Then thinking about it further, why is this a block not just circles?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mhupp

  • Bull Frog
  • Posts: 250
Re: LISP to draw circle and make block
« Reply #18 on: May 26, 2022, 12:25:50 PM »
@mhupp
FWIW, you should check the existence of the number before dividing otherwise it'll throw an error. I also like to use GETDIST for these types of inputs since you can enter a number as well as pick two points :)
Code - Auto/Visual Lisp: [Select]
  1. (and (setq rad (getdist "\nCircle Diameter: "))
  2.      (setq rad (/ rad 2))
  3.      (setq pt (getpoint "\nPick Center Point of Circle: "))
  4. )

It is checking when asking for the number. if it isn't inputted then the if statement fails. NM i see what your talking about.
added it to the entmake just to be different  :whistling:

Code - Auto/Visual Lisp: [Select]
  1. (entmake (list '(0 . "CIRCLE") '(8 . "Fulcrum") (cons 10 pt) (cons 40 (/ rad 2))))

Usually use getdist for those reason and you can also input fractions like 1-3/4 for 1.750 or use 100' for 1200.
I also brought up using a dynamic block but they said they wanted unique blocks with the time stamp. 

¯\_(ツ)_/¯
« Last Edit: May 26, 2022, 12:49:49 PM by mhupp »

like_citrus

  • Newt
  • Posts: 114
Re: LISP to draw circle and make block
« Reply #19 on: May 26, 2022, 08:22:53 PM »
Hi, this is working now for the diameter, thanks and much appreciate it.

Quote
What do you use these for? Have you thought about using a circle block ( as mentioned above ) then changing the scale to get the correct size? Then you wouldn't have a bunch of blocks with different names that look the same but only have a different radius.
What I often do is create blocks from scratch. As a base point, I draw a circle and place it in a layer that is not printed (in this case Fulcrum). Then make it into a block manually.
The timestamp is to differentiate blocks, so each block will in the end be different.
It's the way that I'm used to working, it may not be the right way but it makes it easier for me.