In this thread...
...HMSilva offers a function "GetVLA_BName", which uses the classic ssget "x" method to find an insert based on block name:
(ssget "_X" (list '(0 . "INSERT") (cons 2 BName)))
Is there an equivalent "VL" (vl, vla, etc.) method to accomplish the same thing? (Something like "vla-get-objectname", but more like "vla-get-blockobjectname".)
What I'm hoping is that there is a way to find a particular block insert (by its block name) in a dwg that is open but not the current dwg.
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
You need to iterate the appropriate layout, inspecting each entity for object type, and for those that pass inspect for Name and/or EffectiveName properties.
Thanks for your response. Sounds simple...
Okay, let's take each piece in order:
1. iterate the appropriate layout - This is always "model", so this is where I am so far:
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
(vlax-for ent (vla-get-modelspace doc)...
(Unfortunately, I haven't figured out a way to test this part, yet, but I've seen it used in code samples.)
2. inspecting each entity for object type - this is where I fall down. I want to find the first instance of a specific block insert (by block name) among all objects/entities in the model space of each open doc, but I cannot use ssget because I want this function to loop through all open docs (not just the active doc).
3. for those that pass, inspect for Name and/or EffectiveName properties - this is what I have (so far) to get me started (I hope):
(vlax-get-property ent
(if (vlax-property-available-p ent 'EffectiveName) 'EffectiveName 'Name)
)
Sure could use a hand (or two).
Here's a quick example demonstrating how to iterate over all open documents and retrieve a list of all block references with a given name; the function below will return a list of VLA block reference objects, grouped by document name:
(defun getblocks ( blk / lst tmp ) (setq blk (strcase blk)) (vlax-for doc (vla-get-documents (vlax-get-acad-object)) (vlax-for obj (vla-get-modelspace doc) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (= blk (strcase (LM:blockname obj))) ) (setq tmp (cons obj tmp)) ) ) (if tmp (setq lst (cons (cons (vla-get-name doc) tmp) lst) tmp nil ) ) ) lst ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) (vl-load-com) (princ)
Call the function with the name of the block to be retrieved.
Track down the acadauto.chm help file - this contains the COM Object model map along with listings for methods and properties. This can really help understand the why's of the VLA- functions.
Entities in model space are members of a collection. The collection is just a holding bag and doesn't have a means of returning all entities of type "X" or having property value of "Y", so you have to iterate each one in turn.
Thanks very much, Lee. That helped a lot, particularly this part:
(if (and (= "AcDbBlockReference" (vla-get-objectname obj))
(= blk (strcase (LM:blockname obj)))
)...
(I modified it some: since none of the blocks I will be looking for are dynamic, I actually don't need to use the LM:blockname function.)
I still have quite a bit of other stuff to figure out for the overall function, but getting over this "hurdle" is a relief.
I do use that Help file from time to time, but I'm still on a steep part of the learning curve with some of this stuff.
Thanks again for your input.
You're most welcome dmfrazier - if you have any questions about the posted code, feel free to ask.
Cheers,
Lee
i'm trying to recall the function with the block name but still it gives me unknown command
really appreciated, as im having 2 blocks with same xdata so i want to recall both as it was not duplicated over each other.