Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP routine for manipulating Blocks after Exploding

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
crosby.109
506 Views, 5 Replies

LISP routine for manipulating Blocks after Exploding

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).

Tags (1)
5 REPLIES 5
Message 2 of 6
dbroad
in reply to: crosby.109

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.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 6
crosby.109
in reply to: dbroad

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.

Message 4 of 6
Lee_Mac
in reply to: crosby.109

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))

 

Message 5 of 6
crosby.109
in reply to: Lee_Mac

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!!!

Message 6 of 6
Lee_Mac
in reply to: crosby.109

crosby.109 wrote:

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 Smiley Wink

 

crosby.109 wrote:

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost