So I have the following which explodes and then send the objects to a subroutine. I am trying to take in all of the exploded blocks, search for a block name, find and replace value of an attribute inside that block base off of a list Attrib_Lst.
I keep getting: "Bad Argument Type: VLA-Object ..." at vla-get-blocks and vla-get-attibutes
Typical format for Attrib_Lst is a list of lists for reasons outside of this scope.
(setq blks (vlax-invoke iBlk 'Explode)) (vl-setattributevalues blks (cdr (car Attrib_Lst))) WHERE:
(defun vl-setattributevalues ( blks lst / itm pos )
;;(foreach blk blks
(foreach blk (vlax-safearray->list (vlax-variant-value (vla-get-blocks blks)))
(if (setq pos (position (vla-get-effectivename blk) lst))
(foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes blk)))
(if (eq (vla-get-tagstring att) (nth (+ pos 1) lst))
(vla-put-textstring att (nth (+ pos 2) lst))
)
)
)
)
)
Any ideas why this sin't working? Sorry if it is obvious. I think I am using it incorrectly (Block Reference vs Block Object).
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Sorry but I am missing the point of your routine. Once you explode a block reference with attributes, all you have is the objects, nested blocks, and attribute definitions that make up the block definition, not the attributes. Even if you could change the attribute definitions default value, what would it be worth?
Why explode your block references so that you can change attribute values?
vla-get-attributes only works when the object is a block reference.
The blocks being exploded have nested blocks inside of them with attributes inside those blocks. So you explode the first layer to get a list of all of the inside blocks and then find the attributes of a certain block to update.
Sorry if I wasn't clear. I could be going about it the wrong way also.
By using the function vla-get-blocks, you are attempting to retrieve the ActiveX blocks property of the supplied VLA-Object. The ActiveX blocks property is a property of the Document object, and represents the Block Collection of the current drawing (i.e. the collection of all Block Definitions in the active drawing, including the definitions of the Modelspace & Paperspace blocks). The argument you are passing to your vl-setattributevalues function is of list data type (as returned by vlax-invoke after applying the ActiveX explode method), and hence does not contain any ActiveX properties/methods.
Without knowing the format of your Attrib_Lst variable, or the code for your position function, consider the following code:
(defun foo ( exl lst / pos ) (foreach obj exl (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (setq pos (position (vla-get-effectivename obj) lst)) ) (foreach att (vlax-invoke obj 'getattributes) (if (= (vla-get-tagstring att) (nth (+ 1 pos) lst)) (vla-put-textstring att (nth (+ 2 pos) lst)) ) ) ) ) )
Called with:
(foo (vlax-invoke iblk 'explode) (cdar attrib_lst))
Lee!
I was hoping someone like you would jump in 🙂
So you got me past that error and I will need to do some studying later to understand what you said, but I forgot that AutoCAD doesn't understand the function "position" . . .
The data is formated as such:
(BlockName1,Attribute1,Value1,BlockName2,Attribute2,Value2,...)
Thanks!!!
Lee!
I was hoping someone like you would jump in 🙂
Thank you for your kind words - though, I'm sure Doug (dbroad above) would also have done a fine job of assisting you
So you got me past that error and I will need to do some studying later to understand what you said, but I forgot that AutoCAD doesn't understand the function "position" . . .
Changing position to vl-position should fix this error - in my earlier post I was unsure whether or not position was a user-defined function.
Lee