Hi @xmarcs and welcome to CADTutor - I'm delighted that you could fine my code (and this thread) useful.
In response to the point you raise regarding attributed blocks:
The reason that the code will presently only operate on attributed blocks is due to the presence of DXF group 66 in the ssget filter list; an entry of (66 . 1) in the DXF data of an INSERT entity indicates that ATTRIB entities follow the INSERT in the drawing database, i.e. the block is attributed.
For your task, assuming I have understood correctly, I would suggest the following function, accepting three arguments:
(defun vsfromatt ( src-blk src-tag tgt-blk / e i n o s v x )
(if
(setq s
(ssget "_X"
(list
'(000 . "INSERT")
'(-04 . "<OR")
'(-04 . "<AND")
'(066 . 1)
(cons 002 (strcat "`*U*," src-blk))
'(-04 . "AND>")
(cons 002 (strcat "`*U*," tgt-blk))
'(-04 . "OR>")
)
)
)
(progn
(setq i -1)
(while (and (setq e (ssname s (setq i (1+ i)))) (not (and x v)))
(setq o (vlax-ename->vla-object e)
n (strcase (vlax-get-property o (if (vlax-property-available-p o 'effectivename) 'effectivename 'name)))
)
(cond
( (and (null v) (= n (strcase src-blk)))
(princ (strcat "\nFound source block \"" src-blk "\" with handle \"" (vla-get-handle o) "\"."))
(if (setq v (LM:vl-getattributevalue o src-tag))
(princ (strcat "\nFound attribute with tag \"" src-tag "\" and value \"" v "\"."))
(princ (strcat "\nAttribute with tag \"" src-tag "\" not found in block \"" src-blk "\"."))
)
)
( (and (null x) (= n (strcase tgt-blk)))
(princ (strcat "\nFound target block \"" tgt-blk "\" with handle \"" (vla-get-handle o) "\"."))
(setq x o)
)
)
)
(cond
( (null v)
(princ (strcat "\nNo attributed blocks with name \"" src-blk "\" containing attribute \"" src-tag "\" were found."))
)
( (null x)
(princ (strcat "\nNo dynamic blocks with name \"" tgt-blk "\" were found."))
)
( (null (LM:setvisibilitystate x v))
(princ (strcat "\nUnable to set visibility state of block \"" tgt-blk "\" to \"" v "\"."))
)
( (princ (strcat "\nVisibility state of block \"" tgt-blk "\" set to \"" v "\".")))
)
)
(princ (strcat "\nNo references of either block \"" src-blk "\" or \"" tgt-blk "\" found in the active drawing."))
)
(princ)
)
(vl-load-com) (princ)
The above references several of my Dynamic Block Functions and Attribute Functions which you may download from my site, or earlier in this thread to support the operation of the above function.
To evaluate the above function, you would define a basic program such as the following:
(defun c:test ( )
(vsfromatt "AttributedBlock1" "AttributeTag1" "DynamicBlock2")
)
In this way, you can operate on multiple blocks with difference names & attribute tags by simply evaluating the function with different arguments.
This function assumes that you have a single reference of the attributed block & dynamic block (else, how would the program know which attribute value to use with which dynamic block reference), and the program incorporates several efficiency improvements:
Rather than nested loops iterating over the set of attributed blocks and then the set of dynamic blocks, this function uses a single loop to iterate over a set containing both references and branches the operation depending on the block reference encountered.
As soon as the function has acquired both the attribute value and target dynamic block, the function will exit the loop and attempt to set the dynamic block visibility state, with no additional iterations.