# Thread: Extract center point and diameter of circle - then use these values in a routine...?

1. ## Extract center point and diameter of circle - then use these values in a routine...?

Registered forum members do not see this ad.

Hi Guys,

I have a simple routine that will allow me to insert a block at a location, scale and rotation which are all determined by user inputs.

The block is a hatched (solid) circle with crosshairs through it which we use to represent holes (steel detailing).

Currently the routine asks the user for an insert point (which we pick at the center of an existing un-hatched circle), hole diameter and rotation angle.

I would like to revise the routine so that it will only ask the user to select the existing circle and the routine will determine the insertion point and size by reading the values from the circle picked.

Code:
```(defun C:HP (/ PT1 BOLTDIA)
(setvar "cmdecho" 0)
(setvar "osmode" 32)
(SETQ PT1 (GETPOINT "\nPick Insertion Point. "))
(SETQ BOLTDIA (ureal 1 "" "Enter Hole Diameter" 22))
(COMMAND "INSERT" "HP" PT1 BOLTDIA "")
(princ)
)```
Is the current routine.

Can someone please educate me as to which lisp functions to use (to extract center and diameter of circle) and how i can apply them to this routine?

Any help is greatly appreciated.

Thanks guys.

2. You may be look into dxf 10 and 40 of a circle object.
Code to get dxf sth like : (cdr (assoc DXF_code entity_record))
Code:
```(setq circleObj (car(entsel "\nSelect circle :"));Get ename of circle object picked

(setq  e_circleObj (entget circleObj)) ; Get record of Entity Circle
(setq CenterPoint (cdr (assoc 10 e_circleObj))) ; Get Center Point by dxf 10
(setq Radius (cdr (assoc 40 e_circleObj))) ; Get Radius by dxf 40```
Archive :
(setq CenterPoint (cdr(assoc 10 (setq e_circleObj (entget(car(entsel "\nSelect Circle :"))))))
Or maybe use VL:
Code:
```(setq vla_circle (vlax-ename->vla-object (car (entsel "\nSelect Circle :"))) ;Get VLA Object Circle by (vlax-ename->vla-object ename)
center (vlax-get  vla_circle 'center)
)```

3. This way ?

Code:
```(defun c:test (/ ss j sset)
;; == Tharwat 01. 09. 2011 == ;;
(if (and
(progn
(print "-->> Select Circle(s) please :")
(setq ss (ssget '((0 . "CIRCLE"))))
)
(tblsearch "BLOCK" "HP")
)
(repeat (setq j (sslength ss))
(setq sset (ssname ss (setq j (1- j))))
(entmakex
(list '(0 . "INSERT")
'(2 . "HP")
(cons 10 (trans (cdr (assoc 10 (entget sset))) 1 0))
'(41 . 1.0)
'(42 . 1.0)
'(43 . 1.0)
'(50 . 0.0)
)
)
)
(cond ((not ss) (alert "You did not select any Circle !! "))
(t
"Your block (HP) is not existed in the current drawing !! "
)
)
)
)
(princ)
)```
Tharwat

4. Of course, this is garbage if you have to specify the rotation. What determines that?

Code:
```(defun c:Test (/ ss i data dxf40)
(if (cond ((tblsearch "BLOCK" "HP"))
((findfile "HP.dwg") (command "_.-insert" "HP.dwg" nil) T)
)
(if (setq ss (ssget '((0 . "CIRCLE"))))
(repeat (setq i (sslength ss))
(entmakex (list '(0 . "INSERT")
'(2 . "HP")
(assoc 10 (setq data (entget (ssname ss (setq i (1- i))))))
(cons 41 (setq dxf40 (cdr (assoc 40 data))))
(cons 42 dxf40)
(cons 43 dxf40)
)
)
)
)
(alert "Block \"HP\" cannot be found!")
)
(princ)
)```

5. thanks a lot for all your help guys, i will test out those routines and let you know how i go.

alanjt - the rotation angle of the hole symbol would need to be in the same direction (square to) the direction of the member. It would probably be a good idea for me to set the default rotation of the symbol to zero, then the user can rotate manually after the block has been inserted.

Thanks again guys.

-----------EDIT----------

After quickly testing those routines, i have found that they both insert the symbol block by picking circle(s) - which is great.

Tharwat - i found that your routine didnt scale the inserted block to suit the size of the circle picked - the block (HP) just came in at the original scale.

alanjt - i found that your routine manages to scale the inserted block by only half the required size (im guessing the routine measured the radius rather than the diameter of the circle picked). I resolved this easily by scaling up the block in the source DWG by x2.

Thanks again for your help guys, im thrilled with the way this routine runs now - it will save us lots of time in the office (and also improve our drawing presentation).

Cheers.

6. Originally Posted by lamensterms
thanks a lot for all your help guys, i will test out those routines and let you know how i go.

alanjt - the rotation angle of the hole symbol would need to be in the same direction (square to) the direction of the member. It would probably be a good idea for me to set the default rotation of the symbol to zero, then the user can rotate manually after the block has been inserted.

Thanks again guys.

-----------EDIT----------

After quickly testing those routines, i have found that they both insert the symbol block by picking circle(s) - which is great.

Tharwat - i found that your routine didnt scale the inserted block to suit the size of the circle picked - the block (HP) just came in at the original scale.

alanjt - i found that your routine manages to scale the inserted block by only half the required size (im guessing the routine measured the radius rather than the diameter of the circle picked). I resolved this easily by scaling up the block in the source DWG by x2.

Thanks again for your help guys, im thrilled with the way this routine runs now - it will save us lots of time in the office (and also improve our drawing presentation).

Cheers.
I'm such a tard. You are correct, I wasn't thinking about diameter. Try this:

Code:
```(defun c:Test (/ ss i data dia)
(if (cond ((tblsearch "BLOCK" "HP"))
((findfile "HP.dwg") (command "_.-insert" "HP.dwg" nil) T)
)
(if (setq ss (ssget '((0 . "CIRCLE"))))
(repeat (setq i (sslength ss))
(entmakex (list '(0 . "INSERT")
'(2 . "HP")
(assoc 10 (setq data (entget (ssname ss (setq i (1- i))))))
(cons 41 (setq dia (* (cdr (assoc 40 data)) 2.)))
(cons 42 dia)
(cons 43 dia)
)
)
)
)
(alert "Block \"HP\" cannot be found!")
)
(princ)
)```

7. haha, thanks a lot for fixing that up alanjt. The routine works brilliantly.

I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.

Thanks again mate.

8. Originally Posted by lamensterms
haha, thanks a lot for fixing that up alanjt. The routine works brilliantly.

I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.

Thanks again mate.
Not a problem.

I have a new link bookmarked at work, but I won't be back in until Monday, but I had this one saved in a txt file: http://images.autodesk.com/adsk/files/acad_dxf1.pdf

9. Fantastic - thanks again alanjt. That will come in very handy once i start learning how to use them.

Cheers.

10. Registered forum members do not see this ad.

Originally Posted by lamensterms
I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.
I find an online reference is sometimes easier to navigate, here is a list of references that may also help you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts