<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Count objects at a specific distance in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085730#M82997</link>
    <description>&lt;DIV&gt;&lt;FONT&gt;Hello everyone, Is there a way to count only objects at a specific distance?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;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?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;In the attached dwg example, I want to delete only those with the green circle.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;Thanks in advance for the help you are giving me !!&lt;/FONT&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 14 Oct 2019 18:12:24 GMT</pubDate>
    <dc:creator>adaptacad</dc:creator>
    <dc:date>2019-10-14T18:12:24Z</dc:date>
    <item>
      <title>Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085730#M82997</link>
      <description>&lt;DIV&gt;&lt;FONT&gt;Hello everyone, Is there a way to count only objects at a specific distance?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;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?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;In the attached dwg example, I want to delete only those with the green circle.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;Thanks in advance for the help you are giving me !!&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Oct 2019 18:12:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085730#M82997</guid>
      <dc:creator>adaptacad</dc:creator>
      <dc:date>2019-10-14T18:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085753#M82998</link>
      <description>&lt;P&gt;In your drawing there is only one block at the "MAXIMUM" distance, and two that are close; unless you mean at a distance greater than a supplied distance.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 18:23:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085753#M82998</guid>
      <dc:creator>dlanorh</dc:creator>
      <dc:date>2019-10-14T18:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085808#M82999</link>
      <description>&lt;P&gt;Here is a quick and dirty. You can easily edit it to suit your exact needs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;(defun c:test ( / ent poly sel maxDist ctr blocks)

(while (not ent) (setq ent (entsel "\nSelect a Polyline")))
(setq poly (vlax-ename-&amp;gt;vla-object (car ent)))
(setq sel (ssget "X" '((0 . "INSERT"))))
(setq maxDist 2)
(setq blocks (ssadd))

(setq ctr 0)
(repeat (sslength sel)
(setq pt (cdr (assoc 10 (entget (ssname sel ctr)))))
(if (&amp;lt; (distance (vlax-curve-getclosestpointto poly pt) pt) maxDist)
(ssadd (ssname sel ctr) blocks)
)

(setq ctr (1+ ctr))
)

(princ (strcat "\n" (itoa (sslength blocks)) " blocks are in range."))
(princ)
)&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Oct 2019 18:47:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085808#M82999</guid>
      <dc:creator>doaiena</dc:creator>
      <dc:date>2019-10-14T18:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085819#M83000</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1166654"&gt;@doaiena&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Here is a quick and dirty. You can easily edit it to suit your exact needs.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;(defun c:test ( / ent poly sel maxDist ctr blocks)

(while (not ent) (setq ent (entsel "\nSelect a Polyline")))
(setq poly (vlax-ename-&amp;gt;vla-object (car ent)))
(setq sel (ssget "X" '((0 . "INSERT"))))
(setq maxDist 2)
(setq blocks (ssadd))

(setq ctr 0)
(repeat (sslength sel)
(setq pt (cdr (assoc 10 (entget (ssname sel ctr)))))
(if (&amp;lt; (distance (vlax-curve-getclosestpointto poly pt) pt) maxDist)
(ssadd (ssname sel ctr) blocks)
)

(setq ctr (1+ ctr))
)

(princ (strcat "\n" (itoa (sslength blocks)) " blocks are in range."))
(princ)
)&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;This is almost !!&lt;BR /&gt;How to use the selection set? and how to delete objects not being counted?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 18:52:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085819#M83000</guid>
      <dc:creator>adaptacad</dc:creator>
      <dc:date>2019-10-14T18:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085856#M83001</link>
      <description>&lt;P&gt;Give this a try.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;(defun c:test ( / ssPoly ssBlocks maxDist polyColors blocks ssDelete ctr poly ctr2 pt)

(setq ssPoly (ssget "X" '((0 . "LWPOLYLINE"))))
(setq ssBlocks (ssget "X" '((0 . "INSERT"))))
(setq maxDist 2)
(setq polyColors (list 1 4))
(setq blocks (ssadd))
(setq ssDelete (ssadd))

(setq ctr 0)
(repeat (sslength ssPoly)
(setq poly (vlax-ename-&amp;gt;vla-object (ssname ssPoly ctr)))

(if (member (vla-get-color poly) polyColors)
(progn

(setq ctr2 0)
(repeat (sslength ssBlocks)
(setq pt (cdr (assoc 10 (entget (ssname ssBlocks ctr2)))))
(if (&amp;lt; (distance (vlax-curve-getclosestpointto poly pt) pt) maxDist)
(ssadd (ssname ssBlocks ctr2) blocks)
)

(setq ctr2 (1+ ctr2))
);repeat blocks

));if red or teal

(setq ctr (1+ ctr))
);repeat polys



(setq ctr 0)
(repeat (sslength ssBlocks)
(if (not (ssmemb (ssname ssBlocks ctr) blocks))
(ssadd (ssname ssBlocks ctr) ssDelete)
)
(setq ctr (1+ ctr))
)

(princ (strcat "\n" (itoa (sslength ssDelete)) " blocks are deleted."))
(command "erase" ssDelete "")
(princ)
)&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Oct 2019 19:12:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085856#M83001</guid>
      <dc:creator>doaiena</dc:creator>
      <dc:date>2019-10-14T19:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085896#M83002</link>
      <description>&lt;P&gt;&lt;FONT&gt;This looks like it will work !! thank you very much!&lt;/FONT&gt;&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1166654"&gt;@doaiena&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 19:43:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085896#M83002</guid>
      <dc:creator>adaptacad</dc:creator>
      <dc:date>2019-10-14T19:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085907#M83003</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1166654"&gt;@doaiena&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove the objects found from the initial selection set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(setq sel (ssget "X" '((0 . "INSERT"))))&lt;/P&gt;&lt;P&gt;This create a selection set with all objects in the drawing with the (0 . "INSERT") filter to select only blocks.&lt;/P&gt;&lt;P&gt;adaptacad's routine creates a new selection set, called blocks, to add blocks that are in range.&lt;/P&gt;&lt;P&gt;Then displays how many.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(princ (strcat "\n" (itoa (sslength blocks)) " blocks are in range."))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add this line of code after the PRINC to erase all the other blocks.&lt;/P&gt;&lt;P&gt;(command "erase" "previous" "r" blocks")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Nice routines adaptacad&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 20:03:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085907#M83003</guid>
      <dc:creator>Scottu2</dc:creator>
      <dc:date>2019-10-14T20:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085942#M83004</link>
      <description>&lt;P&gt;note that this is brute force. It tests the distance on every item.&lt;/P&gt;&lt;P&gt;If running on large amounts of items over and over, you can speed things up by doing bounding box elimination.&lt;/P&gt;&lt;P&gt;That is, you make a list of the points to look at, sort by their x coord, then skip the ones before and after the bounding box. Do same for Y once narrowed down.&lt;/P&gt;&lt;P&gt;That sort approach is how you do things fast like "delete duplicate objects" and so on.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 20:16:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9085942#M83004</guid>
      <dc:creator>JamesMaeding</dc:creator>
      <dc:date>2019-10-14T20:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9086149#M83005</link>
      <description>&lt;P&gt;This was also answered &lt;A href="https://www.cadtutor.net/forum/topic/68898-count-objects-at-a-specific-distance/?tab=comments#comment-556529" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;HERE&lt;/STRONG&gt;&lt;/A&gt; too. A few simple changes for speed could also include using vl-some when checking distance of points to lines, use an ename rather than vla object for the closest point check and filter the colored plines directly:&lt;/P&gt;&lt;PRE&gt;(setq sspoly (ssget "X" '((0 . "LWPOLYLINE") (-4 . "&amp;lt;OR") (62 . 1) (62 . 4) (-4 . "OR&amp;gt;"))))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 22:14:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9086149#M83005</guid>
      <dc:creator>ronjonp</dc:creator>
      <dc:date>2019-10-14T22:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9087232#M83006</link>
      <description>&lt;P&gt;&lt;FONT&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/296193"&gt;@JamesMaeding&lt;/a&gt;&amp;nbsp; You are very right. I tested on a file with many objects and behaved slowly!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 12:11:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9087232#M83006</guid>
      <dc:creator>adaptacad</dc:creator>
      <dc:date>2019-10-15T12:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9093161#M83007</link>
      <description>&lt;P&gt;&lt;FONT&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1166654"&gt;@doaiena&lt;/a&gt;&amp;nbsp; and &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/296193"&gt;@JamesMaeding&lt;/a&gt;&amp;nbsp; Is there a way to improve performance? make it faster?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 18:54:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9093161#M83007</guid>
      <dc:creator>adaptacad</dc:creator>
      <dc:date>2019-10-17T18:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count objects at a specific distance</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9094390#M83008</link>
      <description>&lt;P&gt;As mentioned above, this is a brute force approach and as such, it gets exponentially slower, with the increase in entity count.&lt;/P&gt;&lt;P&gt;Both&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/296193"&gt;@JamesMaeding&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/593837"&gt;@ronjonp&lt;/a&gt;&amp;nbsp; gave suggestions on how to improve the performance. You can use a boundingbox elimination approach, filter the polylines at the selection stage, skip the ename-&amp;gt;object convertion and so on. You should at least give it a try on your own, to implement these changes.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 10:47:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/count-objects-at-a-specific-distance/m-p/9094390#M83008</guid>
      <dc:creator>doaiena</dc:creator>
      <dc:date>2019-10-18T10:47:40Z</dc:date>
    </item>
  </channel>
</rss>

