<?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 Attedit: replacing an argument with a variable in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739532#M139724</link>
    <description>&lt;P&gt;Ok, so the quick summary: I'm creating a LISP routine that will use the attedit command to delete the contents of 50+ attributes per drawing (several hundred drawings as well). I need it to be able to delete the contents no matter what was there to begin with (which varies from drawing to drawing). My solution is to delete the contents 1 character at a time by using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "B" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "C" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...and so on...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works wonderfully, but results in a rather long LISP file and since I have to do this for over 50 attributes within the same block (DESCRIPTION_1, DESCRIPTION_2, etc) having to create this LISP routine through copy / paste / edit is going to be painful. I have tried (and failed) several different ways of assigning a variable to "DESCRIPTION_1" so that I can simply change the variable every time that the code needs to move on to the next attribute, but nothing has worked. Below is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(setq DESCR 'DESCRIPTION_1)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;(setq DESCR 'DESCRIPTION_2)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to remove the quotes around the variable and just about every variation that I can think of or search for and haven't been able to get it to work. Can anyone shed some light on a solution for me aside from having to manually edit each line for 1000 of lines of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANKS!&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jul 2015 16:12:33 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-07-24T16:12:33Z</dc:date>
    <item>
      <title>Attedit: replacing an argument with a variable</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739532#M139724</link>
      <description>&lt;P&gt;Ok, so the quick summary: I'm creating a LISP routine that will use the attedit command to delete the contents of 50+ attributes per drawing (several hundred drawings as well). I need it to be able to delete the contents no matter what was there to begin with (which varies from drawing to drawing). My solution is to delete the contents 1 character at a time by using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "B" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "C" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...and so on...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works wonderfully, but results in a rather long LISP file and since I have to do this for over 50 attributes within the same block (DESCRIPTION_1, DESCRIPTION_2, etc) having to create this LISP routine through copy / paste / edit is going to be painful. I have tried (and failed) several different ways of assigning a variable to "DESCRIPTION_1" so that I can simply change the variable every time that the code needs to move on to the next attribute, but nothing has worked. Below is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(setq DESCR 'DESCRIPTION_1)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;(setq DESCR 'DESCRIPTION_2)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to remove the quotes around the variable and just about every variation that I can think of or search for and haven't been able to get it to work. Can anyone shed some light on a solution for me aside from having to manually edit each line for 1000 of lines of code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANKS!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 16:12:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739532#M139724</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-07-24T16:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Attedit: replacing an argument with a variable</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739872#M139725</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;Ok, so the quick summary: I'm creating a LISP routine that will use the attedit command to delete the contents of 50+ attributes per drawing (several hundred drawings as well). I need it to be able to delete the contents no matter what was there to begin with (which varies from drawing to drawing). My solution is to delete the contents 1 character at a time by using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi arrow2486,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="hps"&gt;something like this&lt;/SPAN&gt;, &lt;SPAN class="hps alt-edited"&gt;perhaps&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(vl-load-com)
(defun c:demo (/ attlst i obj s1)
  (if (setq s1 (ssget "_X" '((0 . "INSERT") (2 . "BLOCK1") (66 . 1))))
    (repeat (setq i (sslength s1))
      (setq obj    (vlax-ename-&amp;gt;vla-object (ssname s1 (setq i (1- i))))
            attlst nil
            attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach att attlst
        (if (and (wcmatch (strcase (vla-get-TagString att)) "DESCRIPTION_*")
                 (vlax-write-enabled-p att)
            )
          (vla-put-TextString att "")
        )
      )
    )
  )
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="hps alt-edited"&gt;Hope this helps, &lt;BR /&gt;Henrique&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 18:54:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739872#M139725</guid>
      <dc:creator>hmsilva</dc:creator>
      <dc:date>2015-07-24T18:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Attedit: replacing an argument with a variable</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739958#M139726</link>
      <description>&lt;P&gt;That worked! However as I'm very new to LISP routines and programming, can you (or someone) explain how / why that works so well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANKS!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 19:35:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739958#M139726</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-07-24T19:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Attedit: replacing an argument with a variable</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739998#M139727</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;That worked! However as I'm very new to LISP routines and programming, can you (or someone) explain how / why that works so well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THANKS!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You're welcome, arrow2486&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="hps"&gt;see&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;if it is&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;easier&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;to understand&lt;/SPAN&gt; now&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(vl-load-com)
(defun c:demo (/ attlst i obj s1)
  ; if select all blocks with attributes and named 'BLOCK1'
  (if (setq s1 (ssget "_X" '((0 . "INSERT") (2 . "BLOCK1") (66 . 1))))
    ; set the index variable 'i' with the selection set length,
    ; and repeat the number of previous selected blocks
    (repeat (setq i (sslength s1))
      ; get the 'i' ename from the selection set,
      ; sets the variable 'i' reduced by 1 in each loop
      ; and transform the entity to a VLA-object
      (setq obj    (vlax-ename-&amp;gt;vla-object (ssname s1 (setq i (1- i))))
            ; sets the 'attlst' variable to nil, to ensure that in
            ; the next loop, is setted with the correct attributes only
            attlst nil
            ; sets the 'attlst' variable with the attributes
            ; in the obj block, as a list with VLA-objects
            attlst (vlax-invoke obj 'GetAttributes)
      )
      ; step thru all attributes from the list
      (foreach att attlst
        ; test if TAG is "DESCRIPTION_*"
        (if (and (wcmatch (strcase (vla-get-TagString att)) "DESCRIPTION_*")
                 ; and, test if can be modified
                 (vlax-write-enabled-p att)
            )
          ; if true, put an empty string
          (vla-put-TextString att "")
        )
      )
    )
  )
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Glad I could help&lt;BR /&gt;&lt;BR /&gt;Henrique&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2015 19:59:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/attedit-replacing-an-argument-with-a-variable/m-p/5739998#M139727</guid>
      <dc:creator>hmsilva</dc:creator>
      <dc:date>2015-07-24T19:59:55Z</dc:date>
    </item>
  </channel>
</rss>

