How to determine if block is dynamic?

How to determine if block is dynamic?

mid-awe
Collaborator Collaborator
3,709 Views
16 Replies
Message 1 of 17

How to determine if block is dynamic?

mid-awe
Collaborator
Collaborator

Hi all,

 

Is there a simple process to determine if a block is dynamic? 

 

I need to use the block name and there will only ever be just one in the drawing at a time. An obsolete version of the block has no attributes or anything, while the updated version has two visibility states. I need to detect if the block is dynamic, and if not, I need to redefine the block with the new version.

 

I had set up a lisp that would simply redefine the block in every drawing but for a reason I could not understand, it would fail sometimes. 

 

Also, this is my code for testing, but I keep getting an error:

(IF (= (VLA-GET-ISDYNAMICBLOCK (VLAX-ENAME->VLA-OBJECT (TBLOBJNAME "block" BLKNM))) :VLAX-FALSE)
    (SETQ MSG "NO")
    (SETQ MSG "YES")
  )

The error I get is:

 

error: ActiveX Server returned the error: unknown name: IsDynamicBlock

Please help. Thank you.

 

0 Likes
Accepted solutions (1)
3,710 Views
16 Replies
Replies (16)
Message 2 of 17

hmsilva
Mentor
Mentor
Accepted solution

EDIT:

blknm as a valid blockname

 

(= (vlax-get (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blknm) 'IsDynamicBlock) -1)

 


Henrique

EESignature

Message 3 of 17

mid-awe
Collaborator
Collaborator
No problem; I'm still digging for clues. Thank you.
0 Likes
Message 4 of 17

hmsilva
Mentor
Mentor

HI mid-awe,

I did edit my previous reply.

 

Henrique

EESignature

0 Likes
Message 5 of 17

mid-awe
Collaborator
Collaborator
Thank you =D That did the trick.

(Apparently, I just responded before you made your edit. As soon as I posted, there was your edit. Thank you.)
0 Likes
Message 6 of 17

mid-awe
Collaborator
Collaborator
I was away looking for other solution, thank you again.
0 Likes
Message 7 of 17

hmsilva
Mentor
Mentor

You're welcome, mid-awe!
Glad I could help

Henrique

EESignature

0 Likes
Message 8 of 17

mid-awe
Collaborator
Collaborator
Henrique, Thank you very much.

Can you share any insight into the error? What is the cause, and how does your version avoid it?

I use your code to determine if the block is dynamic, and then if it is I call a sub-function to change the visibility state. The sub-function is now throwing the error, and it worked before. I'm hoping to understand what about my code is not finding the "IsDynamicBlock". Do I need to release the object before calling the subfunction?

Any help is greatly appreciated. Thank you.
0 Likes
Message 9 of 17

hmsilva
Mentor
Mentor

Hi mid-awe,

Using 'TBLOBJNAME' function to get the block ename, and using it as argument to the 'VLAX-ENAME->VLA-OBJECT' function, and dump the object proreties and the supported methods:

_$ (vlax-dump-object (VLAX-ENAME->VLA-OBJECT (TBLOBJNAME "block" "BlockName")) T)
; IAcadEntity2: AutoCAD Entity Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00000001406ea1d8>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000003c25d860>
;   EntityTransparency = "ByLayer"
;   Handle (RO) = "23A"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000000003fe159f8>
;   Layer = "0"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ObjectID (RO) = 42
;   ObjectID32 (RO) = 42
;   ObjectName (RO) = "AcDbBlockBegin"
;   OwnerID (RO) = 43
;   OwnerID32 (RO) = 43
;   PlotStyleName = "ByLayer"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000000003fe15a50>
;   Visible = -1
; Methods supported:
;   ArrayPolar (3)
...
;   Update ()
T
_$

 

we don't have the 'IsDynamicBlock' property avaliable...

We need to use the block from the block collection from the active document to acess to the 'IsDynamicBlock' property and others...

 

_$ (vlax-dump-object (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) "BlockName") T)
; IAcadBlock: A block definition containing a name and a set of objects
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00000001406ea1d8>
;   BlockScaling = 1
;   Comments = ""
;   Count (RO) = 12
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000003c25d860>
;   Explodable = -1
;   Handle (RO) = "217"
;   HasExtensionDictionary (RO) = -1
;   IsDynamicBlock (RO) = -1
;   IsLayout (RO) = 0
;   IsXRef (RO) = 0
;   Layout (RO) = AutoCAD.Application: The property is not available in current state
;   Name = "BlockName"
;   ObjectID (RO) = 43
;   ObjectID32 (RO) = 43
;   ObjectName (RO) = "AcDbBlockTableRecord"
;   Origin = (0.0 0.0 0.0)
;   OwnerID (RO) = 44
;   OwnerID32 (RO) = 44
;   Path = AutoCAD.Application: Not applicable
;   Units = 4
;   XRefDatabase (RO) = AutoCAD.Application: No database
; Methods supported:
;   Add3DFace (4)
...
;   Unload ()
T
_$  

 

'The sub-function is now throwing the error, and it worked before.'

 

It should not, post the sub-function and the code lines where you are setting variables and call the sub-function (if possible)

 

Henrique

EESignature

0 Likes
Message 10 of 17

mid-awe
Collaborator
Collaborator

Ok, that certainly makes things clearer. Below is the info you asked for:

 

(DEFUN CHGVIS (E NEWVAL / OBJ SAL PROPNAME PRP)
  (SETQ	OBJ	 (IF (= (TYPE E) 'VLA-OBJECT) E (VLAX-ENAME->VLA-OBJECT E))
	PROPNAME "Visibility"
  )
  (IF (= (VLAX-GET-PROPERTY OBJ 'IsDynamicBlock) :VLAX-TRUE)
    (PROGN
      (SETQ SAL	(VLAX-SAFEARRAY->LIST (VLAX-VARIANT-VALUE (VLA-GETDYNAMICBLOCKPROPERTIES OBJ)))
	    PRP	(VL-REMOVE-IF-NOT (FUNCTION (LAMBDA (X) (= (VLAX-GET-PROPERTY X 'PROPERTYNAME) PROPNAME))) SAL)
      )
      (MAPCAR (FUNCTION	(LAMBDA	(V) (IF (VLAX-PROPERTY-AVAILABLE-P V 'VALUE) (PROGN (VLAX-PUT-PROPERTY V 'VALUE NEWVAL) (VLA-UPDATE OBJ))))) PRP)
    )
  )
)

(DEFUN ORDER (/ BLK ENM)
  (VL-LOAD-COM)
  (SETQ	BLK "ORDERBOX"
	ENM (TBLOBJNAME "block" BLK)
  )
  (IF (TBLSEARCH "block" "ORDERBOX")
    (IF	(= (VLAX-GET (VLA-ITEM (VLA-GET-BLOCKS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))) BLK) 'ISDYNAMICBLOCK) -1)
      (CHGVIS ENM "YES")
      (PROGN
	(COMMAND "._-insert" (STRCAT BLK "=") (COMMAND))
	(ORDER)
      )
    )
    (PRINC (STRCAT "\n\t !>>" BLK " is not found in current drawing <<!\n"))
  )
)

I believe you have possibly provided the best clue, but I don't want to make the change to the sub-function until I'm certain.

 

Thank you again Henrique.

0 Likes
Message 11 of 17

hmsilva
Mentor
Mentor

mid-awe,

I'm getting confused...

 

Is your goal, to  change the block definition  visibility state?

Or change the insert visibility state?

 

Henrique

EESignature

0 Likes
Message 12 of 17

mid-awe
Collaborator
Collaborator
Sorry for the confusion.

This particular block is part of a template; no need to insert. For backwards compatibility with old drawings, I redefine the old block with the dynamic version before changing the visibility state. It seemed like a good Idea to utilize the same tools for old version and new.

I hope that is more clear.

Thank you again.
0 Likes
Message 13 of 17

hmsilva
Mentor
Mentor

mid-awe,

 

your CHGVIS function acepts as argument a ename or a vlaobject, and is testing for DynaProps...

At ORDER function, you have

  (SETQ BLK "ORDERBOX"
 ENM (TBLOBJNAME "block" BLK)
  )

...

(CHGVIS ENM "YES");<<<<< ENM is the 'Block  Definition', and will throw an error in the CHGVIS function when testing for DynaProps...

(= (VLAX-GET-PROPERTY OBJ 'IsDynamicBlock) :VLAX-TRUE)

 

Probably, just test for Dynamic Props, in the existing 'Block  Definition', and if not dynamic, insert/redefine the block, will suffice.

 

Henrique

EESignature

Message 14 of 17

mid-awe
Collaborator
Collaborator
Thank you again. Everything is working as expected. =D
0 Likes
Message 15 of 17

hmsilva
Mentor
Mentor

@mid-awe wrote:
Thank you again. Everything is working as expected. =D

You're welcome,
Glad you have it sorted!

 

Another way to test the block definition for dynamic properties, might be something like this:

(defun is_dyn (blkname / )
  (if (assoc 360 (entget (cdr (assoc 360 (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" blkname)))))))))
    T
  )
)


Hope this helps,
Henrique

 

EESignature

0 Likes
Message 16 of 17

Anonymous
Not applicable

Above LSP variant doesn't work.

Alternate solution:

 

(defun IsDynBlockDefinition (blkname / )
(member '(3 . "ACAD_ENHANCEDBLOCK") (entget (cdr (assoc 360 (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" blkname)))))))))
)

0 Likes
Message 17 of 17

mid-awe
Collaborator
Collaborator

I'll give it a try.

 

Thank you.

0 Likes