I tried but there was no luck. Some how my dia is not getting correct. and Are not in the block. and there is not group of the circles as shown in the image earlier.
(defun c:CircleTagBlockLoop ()
;; Function to create the circle and block based on user input
(defun create-circle-block (circleTag circleDiam groupCount)
(setq basePt (getpoint "\nSpecify center point for the block: "))
;; Create a new block definition
(setq blockName (itoa circleTag)) ; Block name is the tag itself (converted to string)
;; Start the block definition
(command "_.BLOCK" blockName basePt)
;; Create the circle entity
(setq circle (entmake (list (cons 0 "CIRCLE")
(cons 10 basePt)
(cons 40 (/ circleDiam 2.0))))) ; Circle radius is half of diameter
;; Create the text at the center of the circle
(setq tagPt basePt) ; Text location is the same as circle center
(setq text (entmake (list (cons 0 "TEXT")
(cons 10 tagPt)
(cons 40 10.0) ; Set a fixed text height in decimal units
(cons 1 (itoa circleTag)) ; Circle Tag (converted to string)
(cons 50 0.0) ; Rotation angle
(cons 41 1.0) ; Text scale
(cons 7 "Standard"))))
;; End the block definition
(command "_.END_BLOCK")
;; Place the block based on the number of groups
(repeat groupCount
(command "_.INSERT" blockName basePt 1.0 1.0 0.0) ; Insert the block without scaling (uniform scale = 1.0)
(setq basePt (polar basePt 0.0 (+ circleDiam 5))) ; Move base point horizontally for next circle
)
)
;; Function to ask the user for input values via selection
(defun ask-user-input ()
;; Select an existing TEXT entity for Circle Tag
(setq entTag (entsel "\nSelect text entity for Circle Tag: "))
(if entTag
(setq circleTag (atoi (cdr (assoc 1 (entget (car entTag)))))) ; Convert text content to integer
(progn
(princ "\nInvalid selection.")
(exit))
)
;; Select an existing CIRCLE entity for Circle Diameter
(setq entCircle (entsel "\nSelect circle entity for Circle Diameter: "))
(if entCircle
(setq circleDiam (* 2.0 (cdr (assoc 40 (entget (car entCircle)))))) ; Extract the radius and double it for diameter
(progn
(princ "\nInvalid selection.")
(exit))
)
;; Select an existing TEXT entity for Number of Groups
(setq entGroupCount (entsel "\nSelect text entity for Number of Groups: "))
(if entGroupCount
(setq groupCount (atoi (cdr (assoc 1 (entget (car entGroupCount)))))) ; Convert text content to integer
(progn
(princ "\nInvalid selection.")
(exit))
)
;; Return the selected values as a list
(list circleTag circleDiam groupCount)
)
;; Start the loop to process each selection
(defun process-selection ()
;; Let the user input Circle Tag, Diameter, and Group Count via selection
(setq selectedData (ask-user-input))
;; Extract tag, diameter, and group count from the selected data
(setq circleTag (nth 0 selectedData))
(setq circleDiam (nth 1 selectedData))
(setq groupCount (nth 2 selectedData))
;; Create the circle and block based on the selected data
(create-circle-block circleTag circleDiam groupCount)
;; Ask the user if they want to continue or exit after processing one row
(if (= (strcase (getstring "\nContinue processing another row? (Y/N): ")) "N")
(progn
(princ "\nProcess terminated.")
(exit)
)
)
;; If the user chooses to continue, repeat the process
(process-selection)
)
;; Start the process
(process-selection)
(princ) ; Exit gracefully
)