Author Topic: Determining if a Block is Dynamic  (Read 670 times)

0 Members and 1 Guest are viewing this topic.

bertybassett

  • Mosquito
  • Posts: 3
Determining if a Block is Dynamic
« on: May 16, 2023, 01:36:32 PM »
Hi,

Is it possible to find out if a block is dynamic from its table/definition properties. I can do it by selecting blocks:

(setq myblk (vlax-ename->vla-object(car(entsel))))(vla-get-IsDynamicBlock myblk)

But I don't want to select the block. I just need to know from its definition that it is dynamic or contains a visibility parameter.

Thanks in advance.

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Determining if a Block is Dynamic
« Reply #1 on: May 16, 2023, 03:34:57 PM »
Welcome to TheSwamp :)

Try this:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq myblk (car (entsel)))
  2.   (vla-get-isdynamicblock
  3.               (vla-get-effectivename (vlax-ename->vla-object myblk))
  4.     )
  5.   )
  6. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

bertybassett

  • Mosquito
  • Posts: 3
Re: Determining if a Block is Dynamic
« Reply #2 on: May 17, 2023, 02:31:12 AM »
Hi ronjonp,

Thank you for your response. As I say I can get the result by selecting the block as you have done. What I'm looking for is something along the lines of:

(tblsearch "block" myblk) if my myblk exists then test if it is dynamic. I suppose a work around would be to insert the block, test it, then delete entlast. Just trying to find the cleanest solution possible.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Determining if a Block is Dynamic
« Reply #3 on: May 17, 2023, 05:23:20 AM »
If you look slightly closer at Ron's example, the selection is purely to facilitate acquiring a test block for the purposes of the example - the code is retrieving the value of the isdynamicblock property from the block definition, not the selected reference.

The example could have equivalently been written to provide a block name instead of a selection, e.g.:
Code - Auto/Visual Lisp: [Select]
  1.     (and
  2.         (/= "" (setq blk (getstring t "\nSpecify block name: ")))
  3.         (tblsearch "block" blk)
  4.     )
  5.     (vla-get-isdynamicblock (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk))
  6. )

bertybassett

  • Mosquito
  • Posts: 3
Re: Determining if a Block is Dynamic
« Reply #4 on: May 17, 2023, 06:09:42 AM »
Apologies Ron for not reading properly. Thank you for clarifying Lee.

Goal achieved. Thank you both.

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Determining if a Block is Dynamic
« Reply #5 on: May 17, 2023, 11:50:42 AM »
Apologies Ron for not reading properly. Thank you for clarifying Lee.

Goal achieved. Thank you both.
Glad you got it sorted.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC