Jump to content

Find circle inside the block


Dayananda

Recommended Posts

In my block there is a only one circle included addition to other  entities .

After inserting the block I need to find out the center co-ordinates of that circle.

 

(setq en1(entlast))

 

Link to comment
Share on other sites

Try this

Command FIB (for Find In Block), select block ...

It will print the insert point of the circle within the block, and outside the block (see if this works)

 


(vl-load-com)
 
;; iterates through the items inside a block.  Returns the searched item (for example "CIRCLE")
(DEFUN find_in_block (blkname tag / od_ent res)
  (SETQ od_ent (TBLOBJNAME "BLOCK"  blkname ))
  (WHILE (SETQ od_ent (ENTNEXT od_ent))
    (if (= tag (cdr (assoc 0 (entget od_ent))))
      (setq res od_ent)
    )
  )
  res
)

 

(defun geteffectivename ( ent / )
  (vla-get-Effectivename (vlax-ename->vla-object ent))
)

 

(defun c:fib ( / ent blkname subent ip_ins ang_ins ip ang sc dist)
  (setq ent (car (entsel "\nSelect block: ")))
  ;;(setq blkname (cdr (assoc 2 (entget ent))))
  (setq blkname (geteffectivename ent))
  (setq subent (find_in_block  blkname "CIRCLE"))
  ;; get the Insert Point
  (princ "\nInsert point of the circle inside the block: ")
  (princ (setq ip_ins (cdr (assoc 10 (entget subent)))))
  (setq ang_ins (angle (list 0.0 0.0 0.0) ip_ins))
 
  ;; now let's add that to where the block was inserted, including rotation and scale
  (setq ip (cdr (assoc 10 (entget ent))))
  (setq ang (cdr (assoc 50 (entget ent))))
  (setq sc (cdr (assoc 41 (entget ent))))  ;; I will assume uniform scale
 
  (princ "\nInsert point of the circle outside the block: ")
  (princ
    (polar
      ip
      (+ ang ang_ins)
      (* sc (distance (list 0.0 0.0 0.0) ip_ins) )
    )
  )
 
  (princ)
)
Edited by Emmanuel Delay
  • Thanks 1
Link to comment
Share on other sites

18 hours ago, Emmanuel Delay said:

Try this

Command FIB (for Find In Block), select block ...

It will print the insert point of the circle within the block, and outside the block (see if this works)

  Thanks It is working. 


(vl-load-com)
 
;; iterates through the items inside a block.  Returns the searched item (for example "CIRCLE")
(DEFUN find_in_block (blkname tag / od_ent res)
  (SETQ od_ent (TBLOBJNAME "BLOCK"  blkname ))
  (WHILE (SETQ od_ent (ENTNEXT od_ent))
    (if (= tag (cdr (assoc 0 (entget od_ent))))
      (setq res od_ent)
    )
  )
  res
)

 

(defun geteffectivename ( ent / )
  (vla-get-Effectivename (vlax-ename->vla-object ent))
)

 

(defun c:fib ( / ent blkname subent ip_ins ang_ins ip ang sc dist)
  (setq ent (car (entsel "\nSelect block: ")))
  ;;(setq blkname (cdr (assoc 2 (entget ent))))
  (setq blkname (geteffectivename ent))
  (setq subent (find_in_block  blkname "CIRCLE"))
  ;; get the Insert Point
  (princ "\nInsert point of the circle inside the block: ")
  (princ (setq ip_ins (cdr (assoc 10 (entget subent)))))
  (setq ang_ins (angle (list 0.0 0.0 0.0) ip_ins))
 
  ;; now let's add that to where the block was inserted, including rotation and scale
  (setq ip (cdr (assoc 10 (entget ent))))
  (setq ang (cdr (assoc 50 (entget ent))))
  (setq sc (cdr (assoc 41 (entget ent))))  ;; I will assume uniform scale
 
  (princ "\nInsert point of the circle outside the block: ")
  (princ
    (polar
      ip
      (+ ang ang_ins)
      (* sc (distance (list 0.0 0.0 0.0) ip_ins) )
    )
  )
 
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...