Jump to content

Count objects at a specific distance


Anushka

Recommended Posts

Hello everyone, Is there a way to count only objects at a specific distance?
Example I have several blocks in my drawing and I want to count only those that are at the maximum distance X, from a RED, CIAN polyline ... and delete all others, How to do this?
In the attached dwg example, I want to delete only those with the green circle.
Thanks in advance for the help you are giving me !!

Drawing1.dwg

Link to comment
Share on other sites

Hi,

Something like this?

(defun c:Test (/ int cnt sel ent get bks lws lst len)
  ;;	Tharwat - Date: 14.Oct.2019	;;
  (and (or *gapdis* (setq *gapdis* 1.0))
       (or (initget 6)
           (setq *gapdis*
                  (cond
                    ((getdist
                       (strcat
                         "\nSpecify maximum gap distance between blocks and polylines <"
                         (vl-princ-to-string *gapdis*)
                         "> :"
                       )
                     )
                    )
                    (*gapdis*)
                  )
           )
       )
       (princ "\nSelect Blocks & Polylines : ")
       (setq int -1
             cnt 0
             sel (ssget "_:L" '((0 . "LWPOLYLINE,INSERT")))
       )
       (while (setq int (1+ int)
                    ent (ssname sel int)
              )
         (or (and (= (cdr (assoc 0 (setq get (entget ent)))) "INSERT")
                  (setq bks (cons get bks))
             )
             (setq lws (cons ent lws))
         )
       )
       (mapcar
         '(lambda (w)
            (mapcar
              '(lambda (b / p)
                 (and (setq lst b)
                      (or (< (setq
                               len (distance (vlax-curve-getclosestpointto w (setq p (cdr (assoc 10 b)))) p)
                             )
                             *gapdis*
                          )
                          (equal len *gapdis* 1e-4)
                      )
                      (setq cnt (1+ cnt))
                      (setq bks (vl-remove lst bks))
                 )
               )
              bks
            )
          )
         lws
       )
       (and bks (foreach bk bks (entdel (cdr (assoc -1 bk)))))
  )
  (princ (strcat "\nNumber of blocks retained [ " (if (< 0 cnt) (itoa cnt) "None") " ]."))
  (princ)
) (vl-load-com)

 

  • Thanks 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...