Jump to content
wimal

Circle inside the Block

Recommended Posts

wimal

(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))

In my blocks there is a circle.How can I find out the radius of that

Share this post


Link to post
Share on other sites
dlanorh
Posted (edited)
(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))

In my blocks there is a circle.How can I find out the radius of that

 

 

Are you going to select a lot of blocks or just one?

 

 

If it is just one block you can use

 

 

(setq circle_rad (vla-get-radius (vlax-ename->vla-object (car (nentsel "\nSelect Circle in Block : ")))))

Edited by dlanorh

Share this post


Link to post
Share on other sites
BIGAL

If you dont nentsel a circle or arc then circle_rad will return nil so you may want to wrap it in a check for radius property.

 

This example is check block for attributes

(if (and (vlax-property-available-p ent "hasattributes")
       (vla-get-hasattributes ent)
       (setq atts (vlax-invoke ent "getattributes"))
)

 

[/code]

Share this post


Link to post
Share on other sites
dlanorh
If you dont nentsel a circle or arc then circle_rad will return nil so you may want to wrap it in a check for radius property.

 

This example is check block for attributes

(if (and (vlax-property-available-p ent "hasattributes")
          (vla-get-hasattributes ent)
          (setq atts (vlax-invoke ent "getattributes"))
)

[/code]

 

 

Good point :ouch::oops:

Share this post


Link to post
Share on other sites
dlanorh

This will return the radius of a circle within a block or a circle within a nested block (not tested past 1 nested block)

 

 

 

(vl-load-com)

(defun c:crad ( / ent circle_rad)
 (setq ent (car (nentsel "\nSelect Circle in Block : "))) 
 (if (= (cdr (assoc 0 (entget ent))) "CIRCLE")
   (setq circle_rad (vla-get-radius (vlax-ename->vla-object ent)))
   (alert "Not a Circle")
 )
)

Share this post


Link to post
Share on other sites
Tharwat
(defun c:test (/ ent get)
 (if (setq ent (car (nentsel "\nSelect Circle in Block : ")))
   (if (= (cdr (assoc 0 (setq get (entget ent)))) "CIRCLE")
     (princ (rtos (cdr (assoc 40 get)) 2))
     (alert "Not a Circle")
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
dlanorh
(defun c:test (/ ent get)
 (if (setq ent (car (nentsel "\nSelect Circle in Block : ")))
   (if (= (cdr (assoc 0 (setq get (entget ent)))) "CIRCLE")
     (princ (rtos (cdr (assoc 40 get)) 2))
     (alert "Not a Circle")
   )
 )
 (princ)
)

 

 

doh! :facepalm:

Share this post


Link to post
Share on other sites
wimal

Thanks everybody It was a great help.

Share this post


Link to post
Share on other sites
Tharwat
doh! :facepalm:

 

Just let me what are you thinking of ? :)

Share this post


Link to post
Share on other sites
wimal

(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))

 

I mean there are blocks in my selection set. So I cant directly pick on circle to get the diameter.

Please help me to do that.

Share this post


Link to post
Share on other sites
Tharwat
(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))

 

I mean there are blocks in my selection set. So I cant directly pick on circle to get the diameter.

Please help me to do that.

 

Hi,

 

This should print the radius of circles found in the selected blocks:

(if xss2
 (repeat (setq i (sslength xss2))
   (setq obj (tblobjname "BLOCK" (cdr (assoc 2 (entget (ssname xss2 (setq i (1- i))))))))
   (while (setq obj (entnext obj))
     (and (= (cdr (assoc 0 (setq get (entget obj)))) "CIRCLE")
          (print (cdr (assoc 40 get))))
     )
   )
 )

Share this post


Link to post
Share on other sites
dlanorh
Posted (edited)
Hi,

 

This should print the radius of circles found in the selected blocks:

(if xss2
 (repeat (setq i (sslength xss2))
   (setq obj (tblobjname "BLOCK" (cdr (assoc 2 (entget (ssname xss2 (setq i (1- i))))))))
   (while (setq obj (entnext obj))
     (and (= (cdr (assoc 0 (setq get (entget obj)))) "CIRCLE")
          (print (cdr (assoc 40 get))))
     )
   )
 )

 

 

If the block is scaled then you need to check if the block is uniformly scaled and if it is, multiple the radius from the block def by the xscalefactor to get the true radius:working:

Edited by dlanorh
update

Share this post


Link to post
Share on other sites
Tharwat
If the block is scaled then you need to check if the block is uniformly scaled and if it is, multiple the radius from the block def by the xscalefactor to get the true radius:working:

 

Right on. :thumbsup:

 

But it seems is that the OP deleted one of their replies that they mentioned they wanted to get the radius to re-scale the blocks back to scale. ;)

Share this post


Link to post
Share on other sites
dlanorh
Right on. :thumbsup:

 

But it seems is that the OP deleted one of their replies that they mentioned they wanted to get the radius to re-scale the blocks back to scale. ;)

 

 

No wonder i'm confused :? :itsover:

Share this post


Link to post
Share on other sites
wimal
Posted (edited)

Both of you are correct.We need to resize the block with reference to the circle inside the block. Our blocks are always scaled uniformly. So the above code is fulfill our requirements. Thanks for your valuable time and codes.

Edited by wimal

Share this post


Link to post
Share on other sites
dlanorh
Both of you are correct.We need to resize the block with reference to the circle inside the block. Our blocks are allays scaled uniformly. So the above code is fulfill our requirements. Thanks for your valuable time and codes.

 

If you need to check the blocks scale using lisp, check the scale factor

 

 

(= (cdr (assoc 41 (entget ent))) 1) ;  for "insert" entity

(= (vla-get-xscalefactor blk_obj) 1);  for blk object 

Share this post


Link to post
Share on other sites
wimal
If you need to check the blocks scale using lisp, check the scale factor

 

 

(= (cdr (assoc 41 (entget ent))) 1) ;  for "insert" entity

(= (vla-get-xscalefactor blk_obj) 1);  for blk object 

 

;;;............FIND DETAILS OF CIRCLE INSIDE A BLOCK.........................
(setq xss2 nil)
(setq pt1 (getpoint"\n Select objects by window "))
(setq pt2 (getcorner pt1"\n 2nd corner"))
(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))
(if xss2
 (repeat (setq i (sslength xss2))
 (setq e(entget (ssname xss2 (setq i (1- i)))))
   (setq xscale (cdr(assoc 41 e)))
   (setq obj (tblobjname "BLOCK" (cdr (assoc 2 e))))
  
   (while (setq obj (entnext obj))
     (and (= (cdr (assoc 0 (setq get (entget obj)))) "CIRCLE")
          (setq radius (cdr (assoc 40 get)))
   );and
     );while
   );repeat
 );if
(setq actu_radius (* radius xscale)); present radious of circle
;;;.............................................................................

Share this post


Link to post
Share on other sites
Tharwat

Select similar blocks then from the properties palette you can change the three scales X,Y,Z to 1.0 and that's the shortest way.

Share this post


Link to post
Share on other sites
wimal
Select similar blocks then from the properties palette you can change the three scales X,Y,Z to 1.0 and that's the shortest way.

 

Good idea. thanks a lot.

Share this post


Link to post
Share on other sites
wimal

;;;............FIND DETAILS OF CIRCLE INSIDE A BLOCK.........................
(setq xss2 nil)
(setq pt1 (getpoint"\n Select objects by window "))
(setq pt2 (getcorner pt1"\n 2nd corner"))
(setq xss2 (ssget"C"pt1 pt2  '((0 . "INSERT") )))
(if xss2
 (repeat (setq i (sslength xss2))
 (setq e(entget (ssname xss2 (setq i (1- i)))))
   (setq xscale (cdr(assoc 41 e)))
   (setq obj (tblobjname "BLOCK" (cdr (assoc 2 e))))
  
   (while (setq obj (entnext obj))
     (and (= (cdr (assoc 0 (setq get (entget obj)))) "CIRCLE")
          (setq radius (cdr (assoc 40 get)))
[color="red"](setq center (cdr (assoc 10 get)))[/color]
   );and
     );while
   );repeat
 );if
(setq actu_radius (* radius xscale)); present radious of circle
;;;.............................................................................

 

 

How can I get the present location of the circle.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×