<?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: Read Specific Attribute Tag from Specific Block (no selection) in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316725#M98607</link>
    <description>&lt;P&gt;Thanks for the reply,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6332124"&gt;@serag.hassouna&lt;/a&gt;&amp;nbsp;- I'll give this a try on Monday then and let you know how it went &lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 23:16:20 GMT</pubDate>
    <dc:creator>ebsoares</dc:creator>
    <dc:date>2018-10-05T23:16:20Z</dc:date>
    <item>
      <title>Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316575#M98605</link>
      <description>&lt;P&gt;Hi, everyone.&lt;/P&gt;&lt;P&gt;Would anyone be able to help me create a lisp that looks in the&amp;nbsp;drawing for a specific block, and if it exists then looks for a specific attribute tag in that block, and if it exists AND is not empty stores that info into a variable to be used later?&lt;/P&gt;&lt;P&gt;I've found multiple posts online that do that but start by asking the user to select a block in the drawing, whereas what I am needing is to just call a lisp and, if said block with said attribute exists, get that string variable created/populated (not interested in having to click on anything).&lt;/P&gt;&lt;P&gt;For a sample, the attached&amp;nbsp;drawing contains a block named "NAVFAC_Sheet_Info" and an attribute tag named "SHEET_TITLE_1_OF_1"&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;Edgar&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 21:06:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316575#M98605</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-05T21:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316685#M98606</link>
      <description>&lt;P&gt;I guess this approach would be tackled with something like that&lt;/P&gt;&lt;PRE&gt;(vl-load-com)
(setq blkname (getstring "\nSpecify Block Name: "))
(princ)
(setq block (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blkname)) ;get block's vla-object

(vlax-for obj block
  (if (wcmatch (vla-get-objectname obj) "AcDbAttribute*")
    (progn
      (setq tagstr (vla-get-tagstring block)) ;get Tag String of the attribute
      (setq textstr (vla-get-textstring block)) ;get Text String of the attribute
    );progn [then part]
  );if the object is an attribute tag
);vlax-for&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 22:31:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316685#M98606</guid>
      <dc:creator>serag.hassouna</dc:creator>
      <dc:date>2018-10-05T22:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316725#M98607</link>
      <description>&lt;P&gt;Thanks for the reply,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6332124"&gt;@serag.hassouna&lt;/a&gt;&amp;nbsp;- I'll give this a try on Monday then and let you know how it went &lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 23:16:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316725#M98607</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-05T23:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316739#M98608</link>
      <description>&lt;P&gt;Please try it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;;;**************************************************************************************

(DEFUN GETALLATTRIBUTES-01  (OBJSELECTION /)
  (IF (= (TYPE OBJSELECTION) 'ENAME)
    (SETQ OBJSELECTION (VLAX-ENAME-&amp;gt;VLA-OBJECT OBJSELECTION))
    )
  (IF (VLAX-PROPERTY-AVAILABLE-P OBJSELECTION "hasattributes")
    (IF (= (VLA-GET-HASATTRIBUTES OBJSELECTION) :VLAX-TRUE)
      (VLAX-SAFEARRAY-&amp;gt;LIST
        (VARIANT-VALUE
          (VLA-GETATTRIBUTES OBJSELECTION)
          )
        )
      )
    )
  )


(defun setq-tag-string ()


(setq block-named "NAVFAC_Sheet_Info" )
(setq attribute-tag-named "SHEET_TITLE_1_OF_1")

(setq inserted-block-obj(VLAX-ENAME-&amp;gt;VLA-OBJECT(ssname  (ssget "X" (list ( cons 0 "INSERT") (cons 2  "NAVFAC_Sheet_Info" )))0)))
      
(setq alltributes-list (GETALLATTRIBUTES-01 inserted-block-obj ))
(Foreach  attribute alltributes-list

 (if (= (VLA-GET-TAGSTRING attribute)  attribute-tag-named)   

     (setq att-value (vla-get-textstring attribute))
);end if 
  );end vlax
  att-value
 );END  setq-tag-string

(setq att-value (setq-tag-string))&lt;/PRE&gt;&lt;P&gt;No error check&amp;nbsp; , all variable global.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 23:40:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316739#M98608</guid>
      <dc:creator>devitg</dc:creator>
      <dc:date>2018-10-05T23:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316911#M98609</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use these routines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun gc:getreferences	(bname / blk)
  (if (setq blk (tblobjname "BLOCK" bname))
    (vl-remove-if-not
      (function (lambda (b) (entget b)))
      (gc:massoc 331 (entget (cdr (assoc 330 (entget blk)))))
    )
  )
)

(defun gc:massoc (code alst)
  (if (setq alst (member (assoc code alst) alst))
    (cons (cdar alst) (gc:massoc code (cdr alst)))
  )
)

(defun gc:getattvalue (ent tag / lst val)
  (while (and (not val)
	      (setq lst (entget (entnext ent)))
	      (= "ATTRIB" (cdr (assoc 0 lst)))
	 )
    (if	(= (strcase tag) (cdr (assoc 2 lst)))
      (setq val	 (cdr (assoc 1 lst)))
      (setq ent (cdr (assoc -1 lst)))
    )
  )
  val
)&lt;/PRE&gt;
&lt;P&gt;and the following expression will return a list containing the value of "SHEET_TITLE_1_OF_1" attribute for all inserted block named "NAVFAC_Sheet_Info" (because there might be more than one).&lt;/P&gt;
&lt;PRE&gt;(mapcar
  (function (lambda (x) (gc:getattvalue x "SHEET_TITLE_1_OF_1")))
  (gc:getreferences "NAVFAC_Sheet_Info")
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 06:52:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8316911#M98609</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-06T06:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8317743#M98610</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3111366"&gt;@ebsoares&lt;/a&gt;&lt;BR /&gt;Well, give this a try, I've debugged &amp;amp; modified my initial code snippet &amp;amp; make it as a routine to return the value you need.&lt;BR /&gt;There're 2 types of things to be returned&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Text Strings&lt;/LI&gt;&lt;LI&gt;Prompt Strings&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;the routine's syntax is&lt;/P&gt;&lt;PRE&gt;(getblkattr attr_type)&lt;/PRE&gt;&lt;P&gt;where &lt;EM&gt;attr_type&lt;/EM&gt; is either "text" to get the text string, or "prompt" to get the prompt string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the routine&lt;/P&gt;&lt;PRE&gt;(defun getblkattr (attr_type / blkname tag_str block obj tagstr textstr promptstr)
  (vl-load-com)
  (setq blkname (getstring "\nSpecify Block Name: "))
  (setq tag_str (getstring "\nSpecify Tag Value: "))
  (princ)
  (setq block (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blkname)) ;get block's vla-object

  (vlax-for obj block
    (if (wcmatch (vla-get-objectname obj) "AcDbAttribute*")
      (progn
        (if
	  (wcmatch (setq tagstr (vla-get-tagstring obj)) tag_str)
	  (progn
	    (setq textstr (vla-get-textstring obj));get text string
	    (if
	      (vlax-property-available-p obj 'PromptString)
	      (setq promptstr (vla-get-promptstring obj))
	      );if [getting prompt value if it exists]
	    );progn
	  );if [getting the text string for a specific tag value]
      );progn [then part]
    );if the object is an attribute tag
  );vlax-for

  (cond
    ((wcmatch attr_type "text") textstr)
    ((wcmatch attr_type "prompt") promptstr)
    (t nil)
    );cond [of the value to be returned]
  
);defun [getblkattr]&lt;/PRE&gt;&lt;P&gt;&amp;amp; here is the results from applying this routine on your sample drawing on the command prompt&lt;/P&gt;&lt;PRE&gt;Command: (getblkattr "text")

Specify Block Name: NAVFAC_Sheet_Info

Specify Tag Value: SHEET_TITLE_1_OF_1
"SHEET TITLE"

Command: (getblkattr "prompt")

Specify Block Name: NAVFAC_Sheet_Info

Specify Tag Value: SHEET_TITLE_1_OF_1
"SHEET TITLE (1 OF 1)"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 05:48:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8317743#M98610</guid>
      <dc:creator>serag.hassouna</dc:creator>
      <dc:date>2018-10-07T05:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8317763#M98611</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6332124"&gt;@serag.hassouna&lt;/a&gt;, your routine inspect the block definition (AcDbBlockTableRecord) so when asking for the TextString, it returns the block definition default value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/58962"&gt;@devitg&lt;/a&gt;, I think the OP is about the attribute value (text string) of an inserted block reference (AcDbBlockReference).&lt;/P&gt;
&lt;P&gt;The differences between &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/58962"&gt;@devitg&lt;/a&gt; reply and mine are:&lt;/P&gt;
&lt;P&gt;- &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/58962"&gt;@devitg&lt;/a&gt; returns the attribute value of the first found block reference, I return a list of the attribute values for all inserted block references.&lt;/P&gt;
&lt;P&gt;- &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/58962"&gt;@devitg&lt;/a&gt; uses a selection set (ssget "_X" ...), I directly get the references from the block table record data which is much more efficient than iterating the whole database (what (ssget "_X" ...) does).&lt;/P&gt;
&lt;P&gt;- &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/58962"&gt;@devitg&lt;/a&gt; example will throw an error if none block reference is found (because ssget will return nil), mine will return nil.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 06:49:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8317763#M98611</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-07T06:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8318409#M98612</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3111366"&gt;@ebsoares&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi, everyone.&lt;/P&gt;&lt;P&gt;.......&lt;/P&gt;&lt;P&gt;block in the drawing, whereas what I am needing is to &lt;FONT color="#3366FF"&gt;just call a lisp and, if said block with said attribute exists, get that string variable&lt;/FONT&gt; created/populated (not interested in having to click on anything).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.......&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this code....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will ask you two thing "Block Name" &amp;amp; "&lt;SPAN&gt;Attribute Tag Name" (put this values as per your Block/Attribute details &amp;amp; both are case sensitive)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then the code will give you two things....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1.&amp;nbsp; &amp;nbsp;A&amp;nbsp;single string value/values of Attribute/Attributes (Depends on No. of Blocks in Drawing, each Attribute value is separated by space).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2.&amp;nbsp; &amp;nbsp;A single List of&amp;nbsp;value/values of Attribute/Attributes (Depends on No. of Blocks in Drawing, each Attribute&amp;nbsp;value is separated by inverted commas).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the Drawing do not the contains the Input "Block Name"&amp;nbsp;or "Attribute Tag Name" it will give a message "Input Block/Tag Name not Found"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(It has been tested in "AutoCAD 2007", hope fully it will work in latest version. Otherwise you have to wait till Monday)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 19:33:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8318409#M98612</guid>
      <dc:creator>dbhunia</dc:creator>
      <dc:date>2018-10-07T19:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8318755#M98613</link>
      <description>&lt;P&gt;Today I tested the code in AutoCAD 2017 on your given Drawing, I think you need The attached code.......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works on multiple&amp;nbsp;&lt;SPAN&gt;Blocks in the Drawing (and Depends on No. of Blocks in Drawing, each Attribute value is separated by comma).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the Drawing do not the contains the Input "Block Name"&amp;nbsp;or "Attribute Tag Name" it will give a message "Input Block/Tag Data not Found"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 05:45:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8318755#M98613</guid>
      <dc:creator>dbhunia</dc:creator>
      <dc:date>2018-10-08T05:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8320755#M98614</link>
      <description>&lt;P&gt;Wow - you guys all rock! Great replies.&lt;/P&gt;&lt;P&gt;I'm still on the fence between&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;'s and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5869979"&gt;@dbhunia&lt;/a&gt;'s responses, as they both got exactly what I am looking for.&lt;/P&gt;&lt;P&gt;Again, I really appreciate the time all of you put into helping me.&lt;/P&gt;&lt;P&gt;Edgar&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 20:09:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8320755#M98614</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-08T20:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8320763#M98615</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;That's right, the reason why I've chosen to deal with the block definition is that it ALWAYS exists, however, there would not be any block reference object from the specified block definition in the drawing.&lt;BR /&gt;But I have to note that my routine assumes that the block definition has only 1 attribute that has the specified tag name, even though the routine will not crash if there're many attribute objects within the block definition (&amp;amp; with the same tag name), &amp;amp; I guess it will return the default values for the lastly inserted attribute within that block definition.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 20:13:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8320763#M98615</guid>
      <dc:creator>serag.hassouna</dc:creator>
      <dc:date>2018-10-08T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8335896#M98616</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;I was wondering if you could help me with a couple of refinements:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1)&lt;/STRONG&gt; In the&amp;nbsp;&lt;STRONG&gt;gc:getreferences&lt;/STRONG&gt; function you used an&amp;nbsp;&lt;STRONG&gt;if &lt;/STRONG&gt;function ("if the block is found do this"), so I tried to use it to also act in the case the block was not found ("NAVFAC_Sheet_Info" in the example) and warn the user, such as this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(if (setq blk (tblobjname "BLOCK" bname))
    (vl-remove-if-not
        (function (lambda (b) (entget b)))
        (gc:massoc 331 (entget (cdr (assoc 330 (entget blk)))))
    )
    &lt;FONT color="#0000FF"&gt;(princ "\nBlock not found")&lt;/FONT&gt;
)&lt;/PRE&gt;&lt;P&gt;Problem is, when&amp;nbsp;the block is not found AutoCAD gives me this error:&amp;nbsp;&lt;STRONG&gt;bad argument type: listp "\nBlock not found"&lt;/STRONG&gt; - Do you know how to solve this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2)&lt;/STRONG&gt;&amp;nbsp;Similarly, in the&amp;nbsp;&lt;STRONG&gt;gc:getattvalue&lt;/STRONG&gt; function, if the block is found, but there's no attribute of the name the user provided ("SHEET_TITLE_1_OF_1" in the example), I'd like to warn the user as well, like the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun gc:getattvalue (ent tag / lst val)
    (while
        (and (not val)
            (setq lst (entget (entnext ent)))
            (= "ATTRIB" (cdr (assoc 0 lst)))
        )
        (if (= (strcase tag) (cdr (assoc 2 lst)))
            (setq val (cdr (assoc 1 lst)))
            (setq ent (cdr (assoc -1 lst)))
        )
    )&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;    ; if val = nil, then the attribute was not found (?) - stop function and warn user:&lt;/FONT&gt;
    &lt;FONT color="#0000FF"&gt;(if (not val)
        (princ "\nNo such attribute")
        val
    )&lt;/FONT&gt;
)&lt;/PRE&gt;&lt;P&gt;Problem this time is that, if the attribute is not found, the routine still goes on to rename the&amp;nbsp;layout tab with the string "No such attribute" (which is kinda of funny &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;), instead of stopping the function and warning the user - could you possibly help me here as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be awesome!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Edgar&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 20:30:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8335896#M98616</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-15T20:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336022#M98617</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a little modification of&amp;nbsp;my previous Code..........As per your requirements......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First it check the "BLOCK" existence then it will check for "ATTRIBUTE" existence.......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this......&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 21:44:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336022#M98617</guid>
      <dc:creator>dbhunia</dc:creator>
      <dc:date>2018-10-15T21:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336509#M98618</link>
      <description>&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;;; check if the block table contains the block
(if (tblobjname "BLOCK" "NAVFAC_Sheet_Info")
  ;; check if the block is referenced
  (if (setq references (gc:getreferences "NAVFAC_Sheet_Info"))
    ;; get the attribute values of block references
    (if (setq attValues (mapcar
                          (function (lambda (x) (gc:getattvalue x "SHEET_TITLE_1_OF_1")))
                          references
                        )
        )
      ;; do your stuff with found values
      (foreach val attValues (strcat "\n" val))
      (alert "None attribute found")
    )
    (alert "None reference found")
  )
  (alert "Block not found in the block table")
)&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Oct 2018 05:38:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336509#M98618</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-16T05:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336553#M98619</link>
      <description>&lt;P&gt;If you are using the gc:getattvalue function, i would change the tag comparing &lt;/P&gt;
&lt;P&gt;from&amp;nbsp; (if&amp;nbsp;&amp;nbsp; &amp;nbsp;(= (strcase tag) (cdr (assoc 2 lst)))&lt;/P&gt;
&lt;P&gt;to =&amp;gt; (if&amp;nbsp;&amp;nbsp; &amp;nbsp;(= (strcase tag) (&lt;STRONG&gt;strcase&lt;/STRONG&gt; (cdr (assoc 2 lst))))&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;EM&gt;or =&amp;gt; (if&amp;nbsp;&amp;nbsp; &amp;nbsp;(= tag (cdr (assoc 2 lst))) &lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;because it is possible to have Attrib&amp;amp;AttdefTags with lower case characters.&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;In all cases, it's also a question of how you like to handle duplicate attribute(tags).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 06:18:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8336553#M98619</guid>
      <dc:creator>cadffm</dc:creator>
      <dc:date>2018-10-16T06:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8338772#M98620</link>
      <description>&lt;P&gt;Thanks for the replies, everyone!&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;,&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;I tried the edits you provided&amp;nbsp;and both the block definition and reference portions work well, but I couldn't get the check on the attribute tag name to work. If, for example, I change the attribute tag name to&amp;nbsp;"SHEET_TITLE_1_OF_&lt;/SPAN&gt;&lt;STRONG&gt;foo&lt;/STRONG&gt;&lt;SPAN style="font-family: inherit;"&gt;" (which does not exist) the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;if&lt;/STRONG&gt;&lt;SPAN style="font-family: inherit;"&gt; function still returned true and&amp;nbsp;it never got to the portion&amp;nbsp;(alert "None attribute found").&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Just so you know, to test I just replaced&amp;nbsp;the&amp;nbsp;(foreach val attValues (strcat "\n" val)) line with&amp;nbsp;(alert "Do stuff").&lt;/P&gt;&lt;P&gt;Any chance&amp;nbsp;I am missing something?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 20:05:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8338772#M98620</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-16T20:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8338831#M98621</link>
      <description>&lt;P&gt;Sorry, try this way:&lt;/P&gt;
&lt;PRE&gt;(if (tblobjname "BLOCK" "bloc-att")
  ;; check if the block is referenced
  (if (setq references (gc:getreferences "bloc-att"))
    ;; get the attribute values of block references
    (if (setq attValues
               (vl-remove nil
                          (mapcar
                            (function (lambda (x) (gc:getattvalue x "SHEET_TITLE_1_OF_1")))
                            references
                          )
               )
        )
      ;; do your stuff with found values
      (foreach val attValues (princ (strcat "\n" val)))
      (alert "None attribute found")
    )
    (alert "None reference found")
  )
  (alert "Block not found in the block table")
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 20:33:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8338831#M98621</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-16T20:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Read Specific Attribute Tag from Specific Block (no selection)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8341644#M98622</link>
      <description>&lt;P&gt;Fantastic! Thanks,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;!!!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:56:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/read-specific-attribute-tag-from-specific-block-no-selection/m-p/8341644#M98622</guid>
      <dc:creator>ebsoares</dc:creator>
      <dc:date>2018-10-17T19:56:42Z</dc:date>
    </item>
  </channel>
</rss>

