MAKE CIRCLE BASED ON THE DIAMETER.

MAKE CIRCLE BASED ON THE DIAMETER.

arpansark0544TCX
Advocate Advocate
1,417 Views
21 Replies
Message 1 of 22

MAKE CIRCLE BASED ON THE DIAMETER.

arpansark0544TCX
Advocate
Advocate

Dear All,

 

Can you share me a lisp which makes make circle based on the diameter and other details provided as below.

arpansark0544TCX_0-1727507157825.png

Based on the image the circle shall have tags in them and then this circle and the tag shall form a block. 

 

This block shall be copied based on the number of groups.

 

 

The user will select one row at a time to make user friendly.

 

Or there shall be 4 pop up to select the inputs and 1 to place the circles.

 

Kindly suggest any other user friendly approach if it make the lisp good.

 

 

 

0 Likes
Accepted solutions (4)
1,418 Views
21 Replies
Replies (21)
Message 21 of 22

arpansark0544TCX
Advocate
Advocate

Sir, As we are talking about improving the code please feel to add any function. The excel linked is just a idea. But I am sure that what ever you come up will be the best fro the cad user who has this type of issue. 

Thank you.

 

0 Likes
Message 22 of 22

arpansark0544TCX
Advocate
Advocate

 

 

(defun createCircleBlock (nom dia /)
  (if (not (tblSearch "Block" nom))
    (progn
      (entMake (list (cons 0 "BLOCK") (cons 2 nom) (cons 70 2) (cons 8 "0") (cons 10 (list 0 0 0))))
      (entMake (list (cons 0 "CIRCLE") (cons 8 "0") (cons 10 (list 0 0 0)) (cons 40 (/ dia 2.0)))) ;; Circle with radius based on diameter
      (entmake (list (cons 0 "TEXT") (cons 1 nom) (cons 7 "STANDARD") (cons 8 "0")
                     (cons 10 (list 0.0 0.0 0.0)) (cons 11 (list 0.0 0.0 0.0))
                     (cons 40 (* 0.6 (/ dia 2.0))) ;; Text height set to 60% of the circle's radius
                     (cons 41 1.0) (cons 50 0.0)
                     (cons 71 0) (cons 72 1) (cons 73 2) (cons 210 (list 0.0 0.0 1.0)) (cons 100 "AcDbText")))
      (entMake '((0 . "ENDBLK") (8 . "0")))
    )
  )
)

(defun c:CreateCirBlock (/ dia diaent pins qua quaent tag tagent)
  (setq tagent (car (entsel "\nSelect circle tag\n"))) ;; Select the tag for the circle
  (setq diaent (car (entsel "\nSelect diameter\n"))) ;; Select the diameter
  (setq quaent (car (entsel "\nSelect quantity\n"))) ;; Select the quantity of insertions
  (setq tag (cdr (assoc 1 (entget tagent)))
        dia (atof (cdr (assoc 1 (entget diaent))))
        qua (atoi (cdr (assoc 1 (entget quaent))))
  )
  (setq pins (getpoint "\nInsertion point?\n")) ;; Get the insertion point
  (createCircleBlock tag dia) ;; Create the block with the tag as the name and adjust text height
  (setq pins (list (+ (car pins) (/ dia 2.0)) (cadr pins))) ;; Adjust insertion point

  ;; Repeat the insertion based on the quantity
  (repeat qua
    (command "_insert" tag pins "" "" "0") ;; Insert the block without scaling
    (setq pins (list (+ (car pins) dia) (cadr pins))) ;; Move insertion point for the next block
  )

  ;; Change color of selected objects to red (AutoCAD color index 1)
  (entmod (subst (cons 62 1) (assoc 62 (entget tagent)) (entget tagent))) ;; Change tag color to red
  (entmod (subst (cons 62 1) (assoc 62 (entget diaent)) (entget diaent))) ;; Change diameter color to red
  (entmod (subst (cons 62 1) (assoc 62 (entget quaent)) (entget quaent))) ;; Change quantity color to red

  (princ)
)

(prompt "\nThe command is CreateCirBlock, like Create Circle Block\n")
(princ)

This AutoLISP code, CreateCirBlock, creates and inserts a block with a circle and a text label in AutoCAD. The text size adjusts automatically to fit within the circle based on its diameter, ensuring clarity. The code also allows multiple block insertions with consistent spacing, streamlining repetitive tasks.

0 Likes