<?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 Loop on selection set in AUTOLISP in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950588#M105739</link>
    <description>&lt;P&gt;I am trying to write a programme for selecting all polylines in a layer and make their start and end width as 0.&amp;nbsp; The below&amp;nbsp;command&amp;nbsp; works&amp;nbsp; with individual selection of polylines with 4 no. of vertices.&lt;/P&gt;&lt;P&gt;(command "PEDIT" pause "E" "W" "0" "0.0075" "N" "N" "W" "0.0075" "0" "X" "")))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, instead of individual selection, i need a programme which selects all polylines in a layer and makes start and end vertices as 0.&lt;/P&gt;&lt;P&gt;I used following function for selection of all polylines in autocad drawing&lt;/P&gt;&lt;P&gt;(setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i am struggling to pass each object from selection set to PEDIT command in a loop. Can someone provide me the programme/guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Apr 2018 11:34:48 GMT</pubDate>
    <dc:creator>prakash.powergrid</dc:creator>
    <dc:date>2018-04-22T11:34:48Z</dc:date>
    <item>
      <title>Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950588#M105739</link>
      <description>&lt;P&gt;I am trying to write a programme for selecting all polylines in a layer and make their start and end width as 0.&amp;nbsp; The below&amp;nbsp;command&amp;nbsp; works&amp;nbsp; with individual selection of polylines with 4 no. of vertices.&lt;/P&gt;&lt;P&gt;(command "PEDIT" pause "E" "W" "0" "0.0075" "N" "N" "W" "0.0075" "0" "X" "")))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, instead of individual selection, i need a programme which selects all polylines in a layer and makes start and end vertices as 0.&lt;/P&gt;&lt;P&gt;I used following function for selection of all polylines in autocad drawing&lt;/P&gt;&lt;P&gt;(setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i am struggling to pass each object from selection set to PEDIT command in a loop. Can someone provide me the programme/guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 11:34:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950588#M105739</guid>
      <dc:creator>prakash.powergrid</dc:creator>
      <dc:date>2018-04-22T11:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950636#M105740</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically, we use&amp;nbsp; the ssname function with an&amp;nbsp; incremented (or decremented) index in a loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With a (while ...) loop&lt;/P&gt;
&lt;PRE&gt;(if (setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))
  (progn
    (setq i 0)
    (while (setq ent (ssname ss i))
      (command "_.PEDIT" ent "_E" "_W" 0 0.0075 "_N" "_N" "_W" 0.0075 0 "_X" "")
      (setq i (1+ i)
      )
    )
  )
)&lt;/PRE&gt;
&lt;P&gt;With a (repeat ...) loop&lt;/P&gt;
&lt;PRE&gt;(if (setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (1- i))))
    (command "_.PEDIT" ent "_E" "_W" 0 0.0075 "_N" "_N" "_W" 0.0075 0 "_X" "")
  )
)&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Apr 2018 12:48:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950636#M105740</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-04-22T12:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950806#M105741</link>
      <description>&lt;P&gt;Your solution worked perfectly. Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i have another problem. I am trying fix poly line starting and ending width based on number of vertices it has. I have gathered following function for counting number of vertices of selected polyline, which is working perfectly&lt;/P&gt;&lt;P&gt;(defun c:nvert ()&lt;BR /&gt;(vl-load-com)&lt;BR /&gt;(setq Pl_Ent (car (entsel "\nSelect polyline: ")))&lt;BR /&gt;(setq VL_Obj (vlax-ename-&amp;gt;vla-object Pl_Ent))&lt;BR /&gt;(setq endParam (vlax-curve-getEndParam Vl_Obj))&lt;BR /&gt;(setq NumVert (+ 1 endParam))&lt;BR /&gt;(princ (strcat "\n" (rtos NumVert 2 0) " vertices"))&lt;BR /&gt;(princ)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, i am trying to call this function from my main function and take action accordingly. The following code has been used for this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Defun c:width_mgr (/ ss i ent novertex)&lt;BR /&gt;(if (setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Test"))))&lt;BR /&gt;(repeat (setq i (sslength ss))&lt;BR /&gt;(setq ent (ssname ss (setq i (1- i))))&lt;BR /&gt;(setq novertex (nvert ent))&lt;BR /&gt;(cond ((= novertex 4)&lt;BR /&gt;(command "_.PEDIT" ent "_E" "_W" "0" "0.0075" "_N" "_N" "_W" "0.0075" "0" "_X" ""))&lt;BR /&gt;((= novertex 5)&lt;BR /&gt;(command "_.PEDIT" ent "_E" "_W" "0" "0.0075" "_N" "_N" "_N" "_W" "0.0075" "0" "_X" ""))&lt;BR /&gt;((= novertex 6)&lt;BR /&gt;(command "_.PEDIT" ent "_E" "_W" "0" "0.0075" "_N" "_N" "_N" "_N" "_W" "0.0075" "0" "_X" ""))&lt;BR /&gt;((= novertex 7)&lt;BR /&gt;(command "_.PEDIT" ent "_E" "_W" "0" "0.0075" "_N" "_N" "_N" "_N" "_N" "_W" "0.0075" "0" "_X" ""))&lt;BR /&gt;(t ((princ (strcat "\n" (rtos novertex 2 0) " vertices"))))&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;(Defun nvert (ent)&lt;BR /&gt;(vl-load-com)&lt;BR /&gt;(setq Pl_Ent (car ent))&lt;BR /&gt;(setq VL_Obj (vlax-ename-&amp;gt;vla-object Pl_Ent))&lt;BR /&gt;(setq endParam (vlax-curve-getEndParam Vl_Obj))&lt;BR /&gt;(setq NumVert (+ 1 endParam))&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;But it is not working. The error is given below :&lt;BR /&gt;"; error: bad argument type: consp &amp;lt;Entity name: 7ff63e95ab60&amp;gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think some problem with auguments passing from main function,&amp;nbsp; but i could not figure out the problem. Can you please guide me again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 16:37:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950806#M105741</guid>
      <dc:creator>prakash.powergrid</dc:creator>
      <dc:date>2018-04-22T16:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950855#M105742</link>
      <description>&lt;P&gt;I think this code will do the job for you.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(vl-load-com)
(Defun c:width_mgr (/ ss i ent lastSeg obj)

(if (setq ss (ssget "_X" '((0 . "*POLYLINE") (8 . "Test"))))
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))

(if (&amp;gt; (setq lastSeg (- (cdr (assoc 90 (entget ent))) 2)) 0)
(progn
(setq obj (vlax-ename-&amp;gt;vla-object ent))
(vla-setwidth obj 0 0 0.0075)
(vla-setwidth obj lastSeg 0.0075 0)
))
);repeat
)
);defun&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Apr 2018 17:20:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7950855#M105742</guid>
      <dc:creator>doaiena</dc:creator>
      <dc:date>2018-04-22T17:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7951039#M105743</link>
      <description>&lt;P&gt;Thank you.. Worked perfectly&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 20:46:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7951039#M105743</guid>
      <dc:creator>prakash.powergrid</dc:creator>
      <dc:date>2018-04-22T20:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: Loop on selection set in AUTOLISP</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7952967#M105744</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5968998"&gt;@prakash.powergrid&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;.....&amp;nbsp; The below&amp;nbsp;command&amp;nbsp; works&amp;nbsp; with individual selection of polylines with 4 no. of vertices.&lt;/P&gt;
&lt;P&gt;(command "PEDIT" pause "E" "W" "0" "0.0075" "N" "N" "W" "0.0075" "0" "X" "")))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, instead of individual selection, i need a programme which selects all polylines in a layer and makes start and end vertices as 0.&lt;/P&gt;
&lt;P&gt;I used following function for selection of all polylines in autocad drawing&lt;/P&gt;
&lt;P&gt;(setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But i am struggling to pass each object from selection set to PEDIT command in a loop. ....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A typical way to do that, in simplest terms and &lt;EM&gt;if all Polylines on that Layer are in the current space and have 4 vertices:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;(if&lt;/FONT&gt; &lt;FONT color="#000000"&gt;(setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;(repeat (setq n (sslength ss))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#000000"&gt;(command "PEDIT"&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#ff0000"&gt;(ssname ss (setq n (1- n)))&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#000000"&gt;"E" "W" "0" "0.0075" "N" "N" "W" "0.0075" "0" "X" "")&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;)&lt;/FONT&gt;&lt;FONT color="#999999"&gt;; repeat&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;)&lt;/FONT&gt;&lt;FONT color="#999999"&gt;; if&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333333"&gt;It actually counts &lt;EM&gt;down from the end&lt;/EM&gt;&amp;nbsp; of the selection set, because it takes a little less code than starting from the beginning, but presumably the order doesn't matter to your end result.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333333"&gt;It will have trouble if any qualifying Polylines are in different layouts, but if that's possible, it could made to either "find" only those in the current Layout, or switch to the Layout each is in to process it.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 15:46:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/loop-on-selection-set-in-autolisp/m-p/7952967#M105744</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2018-04-23T15:46:12Z</dc:date>
    </item>
  </channel>
</rss>

