Author Topic: Get number of block tags (no selection)  (Read 160 times)

0 Members and 1 Guest are viewing this topic.

Lastknownuser

  • Mosquito
  • Posts: 14
Get number of block tags (no selection)
« on: September 13, 2022, 05:09:20 AM »
Hi! I want to know if its possible to find number and names of block tags in drawing, without selection. Example, I have a block called CONS_C1 with tags NUMBER, HEIGHT, LLC, EEC.
I'd like to, just by knowing name of the block, find out number of tags, and names if possible, but the number is mainly what I want.
I tried the following
Code: [Select]
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq testblock (vla-item (vla-get-blocks doc) "CONS_C1"))
And with
Code: [Select]
(vla-get-count testblock)I get some something (number of tags+1), but not sure if its the best way to do what I need.
Any help welcome, thanks!

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: Get number of block tags (no selection)
« Reply #1 on: September 13, 2022, 06:18:12 AM »
If I got you right, you want to get the number of certain block name inserted into your current DWG then if so here is an example.
NOTE: this works with regular blocks and not with dynamic

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "CONS_C1"))))
  2.   (alert (strcat "Number of blocks found < "
  3.                  (itoa (sslength ss))
  4.                  " >"
  5.          )
  6.   )
  7.   (alert "None found !")
  8. )

Lastknownuser

  • Mosquito
  • Posts: 14
Re: Get number of block tags (no selection)
« Reply #2 on: September 13, 2022, 06:41:31 AM »
If I got you right, you want to get the number of certain block name inserted into your current DWG then if so here is an example.
NOTE: this works with regular blocks and not with dynamic

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "CONS_C1"))))
  2.   (alert (strcat "Number of blocks found < "
  3.                  (itoa (sslength ss))
  4.                  " >"
  5.          )
  6.   )
  7.   (alert "None found !")
  8. )

No, not really. Block is not inerted into drawing model space. I just know the name of the block, that potentially can be inserted (picture 1).
I'd like to find out number and names of that block attribute tags (not values because the block is not inserted of course). So in this case (picture 2), result would be number of tags: 4, and their names (NUMBER, HEIGHT, LLC, EEC)

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: Get number of block tags (no selection)
« Reply #3 on: September 13, 2022, 07:02:41 AM »
Something like this ?

Code - Auto/Visual Lisp: [Select]
  1. (vlax-for itm (vla-item (vla-get-blocks doc) "CONS_C1")
  2.   (and (= (vla-get-objectname itm) "AcDbAttributeDefinition")
  3.        (princ (strcat "\nTag : " (vla-get-tagstring itm) " --- Value : " (vla-get-textstring itm)))
  4.   )
  5. )
  6.  

Lastknownuser

  • Mosquito
  • Posts: 14
Re: Get number of block tags (no selection)
« Reply #4 on: September 13, 2022, 08:10:32 AM »
Something like this ?

Code - Auto/Visual Lisp: [Select]
  1. (vlax-for itm (vla-item (vla-get-blocks doc) "CONS_C1")
  2.   (and (= (vla-get-objectname itm) "AcDbAttributeDefinition")
  3.        (princ (strcat "\nTag : " (vla-get-tagstring itm) " --- Value : " (vla-get-textstring itm)))
  4.   )
  5. )
  6.  

Yes, thank you!

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: Get number of block tags (no selection)
« Reply #5 on: September 13, 2022, 08:13:00 AM »