<?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 Re: Is there a way to check if a block is inserted at a point, or at many points in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011965#M104772</link>
    <description>&lt;P&gt;Interesting. I'm going to make a test with this code and see which works faster.&amp;nbsp;I have another program that could definitely use this. Thank you!!&lt;/P&gt;</description>
    <pubDate>Fri, 18 May 2018 16:58:22 GMT</pubDate>
    <dc:creator>jamieq</dc:creator>
    <dc:date>2018-05-18T16:58:22Z</dc:date>
    <item>
      <title>Is there a way to check if a block is inserted at a point, or at many points?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011805#M104767</link>
      <description>&lt;P&gt;I&amp;nbsp;wrote a program that inserts blocks at midpoints of lines, and it works great. However, some of these lines have blocks inserted at one end of them. I am looking for a way to check if there is a block inserted at either end of each line in my selection set. If there is, then that line is skipped. I've put together some code, and it works, but it has to process a lot of information and has taken a program that executed in less than a second and now takes up to 30 seconds (or likely more if there were more objects in the selection set) to run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I used to collect the insertion points of all the blocks:&lt;/P&gt;&lt;PRE&gt;(defun GetCaps ( / cpss cplst cpt i)
(setq i 0 cplst nil)
(if (setq cpss (ssget "A" (list (cons 0 "insert")(cons 2 "CAP")(cons 410 "Model"))))
(while (not (= i (sslength cpss)))
	(setq cpt (cdr (assoc 10 (entget (ssname cpss i)))))
	(setq cplst (append cplst (list cpt)))
	(setq i (1+ i))
)
nil)
cplst
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I put this into my existing code to evaluate against that list:&lt;/P&gt;&lt;PRE&gt;(setq mch 0)
(foreach x (GetCaps)(if (or (equal x p1)(equal x p2))(setq mch 1)))
(if (= mch 0)
	(progn
		....
	)
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works. But it takes so long it isn't tenable. Any help&amp;nbsp;that would make this run quick is much appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 15:56:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011805#M104767</guid>
      <dc:creator>jamieq</dc:creator>
      <dc:date>2018-05-18T15:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011881#M104768</link>
      <description>&lt;P&gt;Jamie,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first in the (getCaps) function use the (cons) function to build the list of points&lt;/P&gt;&lt;P&gt;cause it turns out that (cons) is faster then (append)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;second in checking point do not use (foreach) cause each&amp;nbsp;iterator (step) you are checking against all points&lt;/P&gt;&lt;P&gt;instead&amp;nbsp;use (while) to stop the loop on success or even better use&amp;nbsp;(vl-some)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and don't forget to&amp;nbsp;eliminate&amp;nbsp;duplicate points.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moshe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:25:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011881#M104768</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2018-05-18T16:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011922#M104769</link>
      <description>&lt;P&gt;I only see a list of block insertion points being created. It would be better to combine all three things together.&lt;BR /&gt;After generating the list of block insertion points, query this list with the end coords of each line using (member). If there is a match skip, if there isn't insert a block at the midpoint.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A slightly more efficient sub would be&lt;/P&gt;&lt;PRE&gt;(defun GetCaps ( / cpss cplst i)
  (setq i 0 cplst nil)
  (if (setq cpss (ssget "X" (list (cons 0 "insert")(cons 2 "CAP")(cons 410 "Model"))))
    (repeat (sslength cpss)
      (setq cplst (cons (cdr (assoc 10 (entget (ssname cpss i)))) cplst)
            i (1+ i)
      )
    )
  )  
cplst
)&lt;/PRE&gt;&lt;P&gt;The more conditional checks you have the slower it will run&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:38:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011922#M104769</guid>
      <dc:creator>dlanorh</dc:creator>
      <dc:date>2018-05-18T16:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011933#M104770</link>
      <description>&lt;P&gt;Thanks for the replies. I'm definitely going to consider them when&amp;nbsp;writing code in the future. I actually&amp;nbsp;found a way to accomplish this in another thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/check-if-block-exists-on-specific-point/td-p/2279813" target="_blank"&gt;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/check-if-block-exists-on-specific-point/td-p/2279813&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that code, instead of compiling a list of all the insertion points of block name CAP and then having to compare the end points of every line in the selection set to that list, now it&amp;nbsp;runs a&amp;nbsp;tiny ssget crossing around each endpoint and checks if there's block inserted there. Program runs just as fast as before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thanks for the help!! I appreciate learning from all the community members here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:44:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011933#M104770</guid>
      <dc:creator>jamieq</dc:creator>
      <dc:date>2018-05-18T16:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011958#M104771</link>
      <description>&lt;P&gt;and here is the code to do it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note that you do to not call (getCaps) more than 1 time&lt;/P&gt;&lt;P&gt;the (vl-some) function stop the loop as soon as the&amp;nbsp;&lt;EM&gt;predicate-function&lt;/EM&gt;&amp;nbsp; return not nil (e.g a positive value) and returns that value to the caller, it only return nil if the &lt;EM&gt;predicate-function&lt;/EM&gt;&amp;nbsp; [(lambda) in this case] does not find a match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does this help you?&lt;/P&gt;&lt;P&gt;moshe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(setq lst (getCaps))

(if (check_points p1 p2)
 (prompt "found.")
 (prompt "not found.")
)

(defun check_points (p1 p2)
 (vl-some
  '(lambda (pt)
    (or (equal pt p1 0.01) (equal pt p2 0.01))
   )
  lst
 )
)&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 16:55:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011958#M104771</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2018-05-18T16:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011965#M104772</link>
      <description>&lt;P&gt;Interesting. I'm going to make a test with this code and see which works faster.&amp;nbsp;I have another program that could definitely use this. Thank you!!&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:58:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8011965#M104772</guid>
      <dc:creator>jamieq</dc:creator>
      <dc:date>2018-05-18T16:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8012203#M104773</link>
      <description>&lt;P&gt;So I decided to add another dimension to my program, and check to see if a block is inserted at the middle of the line as well. I used the code from the link above for the caps, but then used your check_points code for the midpoint block. It was still taking a couple of second. I then dropped the other code and&amp;nbsp;modded yours to check a single point, and now every run through it does three checks with the check_points sub. INSTANT!! It worked instantly!! No delays. It is exactly what I was looking for. Thank you so much!!!&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 19:03:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8012203#M104773</guid>
      <dc:creator>jamieq</dc:creator>
      <dc:date>2018-05-18T19:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a block is inserted at a point, or at many points</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8012222#M104774</link>
      <description>&lt;P&gt;welcome, glad i was helpful &lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://forums.autodesk.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 19:12:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-to-check-if-a-block-is-inserted-at-a-point-or-at/m-p/8012222#M104774</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2018-05-18T19:12:58Z</dc:date>
    </item>
  </channel>
</rss>

