Author Topic: Programmatically checking for block in current drawing.  (Read 1570 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Programmatically checking for block in current drawing.
« on: November 10, 2012, 02:49:30 PM »
When a block is deleted from a sheet (or paper space tab) it is still in the drawing until purged out.  Is there a way to see if a particular block is in the drawing (not purged yet) but not located in a particular paper-space or model tab.  The "attedit" command cannot be performed on a block not within the current tab.  The "tblobjname" function returns the "entname" of the block if it is present anywhere within the drawing, I need to be sure pro-grammatically it is within the current tab also so I can utilize the "attedit" command.  If it is not I can insert, attedit and then delete the block, however I do not want to do this if it already exist on the current tab.

Thanks,

Bruce

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Programmatically checking for block in current drawing.
« Reply #1 on: November 10, 2012, 03:01:48 PM »
Code - Auto/Visual Lisp: [Select]
  1. (tblsearch "BLOCK" <Your-Block-Name>)

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Programmatically checking for block in current drawing.
« Reply #2 on: November 10, 2012, 06:53:16 PM »
Unfortunately that gives me the same results as "tblobjname" does.  It still returns a value even though the block has been erased from the current tab.

I am working around the issue, thanks for your reply.

Bruce

BlackBox

  • King Gator
  • Posts: 3770
Re: Programmatically checking for block in current drawing.
« Reply #3 on: November 10, 2012, 10:14:15 PM »
Bruce,

By searching the Block Table you're querying if a Block Definition exists, rather than if a Block Reference (an entity instance) exists on, or not on any given Layout tab.

To determine if a Block Reference exists within any tab, one would test for a valid Selection Set instead.

Here's a sub-function that can be used to determine if any Block Reference (by name) exists on, or not on any given tab name:

Code - Auto/Visual Lisp: [Select]
  1. (defun _IsBlockOnTab (blockName whatTab)
  2.   ;; Example: Is "MyBlock"  on any tab other than the current tab?
  3.   ;;    (_IsBlockOnTab "MyBlock" (strcat "~" (getvar 'ctab)))
  4.   (if (ssget "_x"
  5.              (list '(0 . "INSERT")
  6.                    (cons 2 blockName)
  7.                    (cons 410 whatTab)
  8.              )
  9.       )
  10.     T
  11.     nil
  12.   )
  13. )
  14.  
"How we think determines what we do, and what we do determines what we get."