Author Topic: How to search for a block name with DBX  (Read 1370 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to search for a block name with DBX
« on: October 16, 2015, 05:07:41 AM »
Hello guys ,

I am trying to modify a specific block name in a bunch of drawings with DBX , everything goes OK but I would like to search for the Block name before running the codes on drawings that may do not have that Block and this would be time consuming.

I tried tblsearch function and it did not return nil when block not found !
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'tblsearch (list "BLOCK" "My Block"))
  2.  

I also tried this .
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'vla-item (list (vla-get-blocks dbx) "My Block"))
  2.  

and it shows that block not found and I am sure the block is existed !

Anyone has any better way ?

Thanks in advance.


Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
How to search for a block name with DBX
« Reply #1 on: October 16, 2015, 05:23:22 AM »
You will need to use something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun item-p ( col itm )
  2.     (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list col itm))))
  3. )
Code - Auto/Visual Lisp: [Select]
  1. (if (item-p (vla-get-blocks dbx) "YourBlock")
  2.     ...
  3. )

Here is an example in working code: Delete Blocks.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to search for a block name with DBX
« Reply #2 on: October 16, 2015, 05:32:21 AM »
Solved, Thank you Lee  :-)

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: How to search for a block name with DBX
« Reply #3 on: October 16, 2015, 05:42:10 AM »
You're most welcome Coder.