MAKE CIRCLE BASED ON THE DIAMETER.

MAKE CIRCLE BASED ON THE DIAMETER.

arpansark0544TCX
Advocate Advocate
1,365 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,366 Views
21 Replies
Replies (21)
Message 2 of 22

john.uhden
Mentor
Mentor

@arpansark0544TCX ,

Is that an AutoCAD table?

The problem I would have is how to determine the table geometry so that the circle blocks are aligned with each row.

Then I presume that the circle diameters are relative to one another but scaled to fit each row vertically.

John F. Uhden

0 Likes
Message 3 of 22

-didier-
Advisor
Advisor

Bonjour @arpansark0544TCX 

 

You don't explain how to select the different parameters.
I write a first version very simple, with selections at screen in the table.

And ask for an insertion point, really very simple.

Here is the appearance of results.

2024-09-28_18-43-17.gif

 

Now you can explain what are you waiting…
Select the table and write automatically at the end of table on the same line ?

I will improve the basic version.

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 4 of 22

arpansark0544TCX
Advocate
Advocate

Yes, this is working exactly the way it is supposed to work.

 

have you checked As mentioned above the individual circles and text(tags) shall be in blocks with block names similar to tag name.

 

 

But, I cannot find the attached code for the same.

 

Thank you.

0 Likes
Message 5 of 22

-didier-
Advisor
Advisor

Bonjour @arpansark0544TCX

 

No, the block has a unique name, and the values (1 2 3...) are attributes.

Do you really need a block named 1, an other 2 and so on ?

If it is the case, blocks exist in the drawing or do I create them by the LSP ?

 

I do not post the code until I’m sure I’m responding correctly to the request.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 6 of 22

arpansark0544TCX
Advocate
Advocate
1. Do you really need a block named 1, an other 2 and so on ?
a. Yes the block should be name same as tags name. for easy management of the circles.
2. If it is the case, blocks exist in the drawing or do I create them by the LSP ?
b. To make sure the block name are unique the working of this lisp will be node in new file to avoid duplicacy.

No, the block has a unique name, and the values (1 2 3...) are attributes.
can we not use attributes.

I do not post the code until I’m sure I’m responding correctly to the request.
That is a great way.
0 Likes
Message 7 of 22

arpansark0544TCX
Advocate
Advocate
I was hoping to get the same results I have shown in the dwg attached.
0 Likes
Message 8 of 22

arpansark0544TCX
Advocate
Advocate

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
)

0 Likes
Message 9 of 22

-didier-
Advisor
Advisor
Accepted solution

Bonjour @arpansark0544TCX 

 

I think it is OK now.

There you can see the operation and result. (Video is impossible to put in the message, it is attached below)

If the block doesn't exist, he will be created.

You type the command name IBTC (Insert Block Tag Circle)

You select the values, in this order, circle tag, circle diameter, number of insertions.

You pick the insertion point. That's all.

 

Problem : If there is an existing block whose name is "1"  or "2" (tag), delete it and purge

because my definition of block will be different of yours.

You can redefine your bloc with a diameter of 0.001, problems because I think in meters.

 

I have ideas for improving this program, but I will wait for your return 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 10 of 22

arpansark0544TCX
Advocate
Advocate
Thank you. I can't thank you enough.
0 Likes
Message 11 of 22

arpansark0544TCX
Advocate
Advocate
I have ideas for improving this program, but I will wait for your return
Sure do let me know.

0 Likes
Message 12 of 22

arpansark0544TCX
Advocate
Advocate
Accepted solution

i edited the code a little for working in MM.

(defun createbloc (nom /)
(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 0.001))) ;; Circle with radius of 0.001
(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.001) (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:IBCT (/ dia diaent ech 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))))
ech (/ (* dia 1000) 2.0) ;; Diameter scaled by 1000
)
(setq pins (getpoint "\nInsertion point?\n")) ;; Get the insertion point
(createbloc tag) ;; Create the block with the tag as the name
(setq pins (list (+ (car pins) (/ dia 2.0)) (cadr pins))) ;; Adjust insertion point
(repeat qua
(command "_insert" tag pins ech "" "0") ;; Insert the block with the scaled diameter
(setq pins (list (+ (car pins) dia) (cadr pins))) ;; Move insertion point for the next block
)
(princ)
)

(prompt "\nThe command is IBCT, like InsertBlockCircleTag\n")
(princ)
0 Likes
Message 13 of 22

arpansark0544TCX
Advocate
Advocate
One such idea to improve the code
1. Can we link Excel with these three specific columns and the code can make the circle block based on it?
0 Likes
Message 14 of 22

-didier-
Advisor
Advisor

Bonjour @arpansark0544TCX 

 

What do you want with Excel ?

No choice in AutoCAD but work with data in Excel ?

I am not sure to understand the question.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 15 of 22

Sea-Haven
Mentor
Mentor

A couple of comments, not sure where the original text and lines came from and why it is not a table ?

 

If this information exists in Excel then yes can make a table and circles etc.

 

For @-didier- you can just select all the text and using a X & Y sort, work out the 3 values for each row, if you want it let me know I do 9 columns and like 200+ rows into a list of rows just using a single window select. 

Message 16 of 22

arpansark0544TCX
Advocate
Advocate
All i am saying is that the code you shared is working perfectly all right. But there is a idea suppose if the user has the complete data of suppose hundreds of rows that he can link that excel and can achieve the same.
0 Likes
Message 17 of 22

arpansark0544TCX
Advocate
Advocate
I suppose that would be great.
0 Likes
Message 18 of 22

Sea-Haven
Mentor
Mentor

Not sure what your asking if you have a table then can use "Table to excel.lsp".

 

Why not have circles inside the table as well ?

 

The select all comment was for @-didier- for inclusion in his code.

Message 19 of 22

-didier-
Advisor
Advisor
Accepted solution

Bonjour

 

@Sea-Haven
Thanks for the idea, I see that we speak the same language because I already had this idea, but I kept it in reserve for an improvement of the code.

 

@arpansark0544TCX 

It is possible to read directly in Excel, even the xlx closed, but this type of link will slow down the operation.

Do you want a global selection in AutoCAD and write the result at the end of the line ?

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 20 of 22

Sea-Haven
Mentor
Mentor
Accepted solution

I disagree "but this type of link will slow down the operation" having played a fair bit with CAD <-> Excel. You can get cell A1 to XXXX235 etc as a range without user input. So know rows and columns etc to getcell value.