MODIFYING SUB-ENTITIES INSIDE A BLOCK

MODIFYING SUB-ENTITIES INSIDE A BLOCK

chaitanya.chikkala
Enthusiast Enthusiast
631 Views
3 Replies
Message 1 of 4

MODIFYING SUB-ENTITIES INSIDE A BLOCK

chaitanya.chikkala
Enthusiast
Enthusiast

HI....

     I AM WRITING A CODE IN WHICH I AM USING DATA OF SUB ENTITIES OF A BLOCK IN AUTOLISP/VISUAL LISP.

PROBLEM :

                   IF ANY TWO BLOCKS HAVE SAME BLOCKREFERENCES...ALL THE SUB-ENTITIES INSIDE THOSE BLOCK REFERENCES ARE HAVING SAME ENTITY NAMES. SO IF I AM DOING ANY OPERATION IN SUB-ENTITY OF A BLOCK, IT IS REFLECTING IN ALL THE BLOCK WITH SAME BLOCK REFERENCE IN WHICH I AM DOING THE OPERATION.

 

                 SO I NEED TO DIFFERENTIATE THE SUB-ENTITIES OF THE BLOCKS WHICH ARE HAVING SAME BLOCK REFERENCES. IS THERE ANY SOLUTION IN AUTOLISP/VISUAL LISP?

 

 

I AM RETREIVING THE SUB-ENTITIES USING THE FOLLOWING FUNCTION:

 ;**********************

(DEFUN RETREIVE_SUB_ENTS ( BLOCKENAME / ENAME SUB_ENT_LIST)
  (IF (SETQ ENAME (TBLOBJNAME "BLOCK" (CDR (ASSOC 2 (ENTGET BLOCKENAME)))))
    (REVERSE
      (WHILE (SETQ ENAME (ENTNEXT ENAME))
 (SETQ SUB_ENT_LIST (CONS ENAME SUB_ENT_LIST))
      )
    )
)(REVERSE SUB_ENT_LIST)
)

;***********************

0 Likes
632 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

@chaitanya.chikkala wrote:

....    IF ANY TWO BLOCKS HAVE SAME BLOCKREFERENCES...ALL THE SUB-ENTITIES INSIDE THOSE BLOCK REFERENCES ARE HAVING SAME ENTITY NAMES. SO IF I AM DOING ANY OPERATION IN SUB-ENTITY OF A BLOCK, IT IS REFLECTING IN ALL THE BLOCK WITH SAME BLOCK REFERENCE IN WHICH I AM DOING THE OPERATION.

 

                 SO I NEED TO DIFFERENTIATE THE SUB-ENTITIES OF THE BLOCKS WHICH ARE HAVING SAME BLOCK REFERENCES. IS THERE ANY SOLUTION IN AUTOLISP/VISUAL LISP?

 

....


It is in the very nature of Blocks [in fact, it's partly the purpose for which Blocks exist] that they are multiple references to the same drawing entities.  If you want to differentiate them with their same entity names, I suppose you could put their entity names from one Block reference into a list, and those from another Block reference into another list, but the lists will have the same contents, and if you do anything to any of the objects, it will still be done to them in all Block references under the same Block name.  You could make a different Block definition from each Block reference [there are routines around to do turn a Block reference into another identical Block but with a different name], but then you would lose most of the advantages of their being Blocks.  Another way to have different entity names for them would be to just Explode all the Blocks, but again....

Kent Cooper, AIA
0 Likes
Message 3 of 4

chaitanya.chikkala
Enthusiast
Enthusiast

Thanks for your response...

 

           All the blocks that I have defined are dynamic blocks...(no static block) and I am controlling each and every block through visual lisp coding, as I am using each block (though identical) differently in the drawing  (so I dont need the same blocks to behave same, if I modify one).

 

           I know that If any dynamic operation is done on a dynamic block, Autocad creates a new block reference and i can differentiate the sub entities inside the block. But if I copy any dynamic block using "CO" command and if i dont do any operation on the copied block, then both the blocks are having the same block reference and all the sub entities inside the block are having the same entity names (though both the blocks are having same entity names).

0 Likes
Message 4 of 4

Anonymous
Not applicable

It sounds like you want to modify the properties of the recently copied block instance. This can be done in visual lisp. Here's a basic example:

  (setq object (vlax-ename->vla-object entname))
  (setq proplist (vla-getdynamicblockproperties object))
  (setq proplist (vlax-variant-value proplist))
  (setq proplist (vlax-safearray->list proplist))
  (foreach item proplist
    (setq tmpname (vla-get-propertyname item))
    (if (= tmpname propname) ; propname is the name of the block parameter
      (vla-put-value
        item
        (vlax-make-variant varval vartype)
      ) ;_ end of vla-put-value
    ) ;_ end of if
  ) ;_ end of foreach

0 Likes