Jump to content

How to update attributes on a single nested block


Whorse

Recommended Posts

We use a large number of blocks, and have created some blocks that are groups of these blocks for specific applications. Problem is, I can't seem to update the attributes on the nested blocks contained within only the block I have just inserted.

 

The only codes I've found online update all the nested blocks in the drawing, and not a specific one.

 

Here's a snippet

 

  
 (setq rm_name (getstring "\nEnter Module Name:      "))
 (setq insertpt (getpoint "\nSelect Insertion Point For Wiring Block:     "))
 (setq wiringblk (vla-insertBlock (vla-get-ModelSpace doc) (vlax-3d-point insertpt) "WIRING-CONTROL-GROUP-ROOF-VENT" 1 1 1 0))

 (vlax-for o (vla-item (vla-get-Blocks doc) "WIRING-CONTROL-GROUP-ROOF-VENT") ;parent block
   (if 
     (and  (eq (vla-get-objectname o) "AcDbBlockReference")
             (eq (vlax-get-property o 'Effectivename) "WIRING-MODULE-2CGROL")) ;child block

     (progn
       (setq olist (vlax-safearray->list
                   (vlax-variant-value (vla-getAttributes o)))) ;list of attributes in child block
          (while (> (vl-list-length olist) 0)
             (setq otag (vla-get-tagstring (car olist)))
             (setq otxt (vla-get-textstring (car olist)))
               (if (and (eq otag "MODULENAME")
                          (eq otxt "RM-01-01"));and
                   (vla-put-textString (car olist) rm_name) ;update textstring
                );if

              (setq olist (cdr olist)) ;counter
              (princ "\n")
       );while
     );progn
   );if
 );vlax-for o

 

I'm getting stuck on how to make sure I'm only updating the block I've inserted. I can see that the variable "wiringblk" is the block reference, but I can't seem to restrict it to only update that block.

 

Thanks to anyone who can help,

 

JB

Link to comment
Share on other sites

If the parent block contains attributed inserts, all inserts of the parent block will have the equal nested block attributes. I think you will have to redefine the block table definition in order to change nested block values and that in turn will update all instances of the block insertions.

 

 

Block Table Information  ....
Select objects: L
1 found

INSERT - TEMP1
 INSERT -TESTB Lay-0 Scl-1.00,1.00,1.00
 ATTRIB     8.0 62.ByLayer  6.ByLayer
 SEQEND     8.0 62.ByLayer  6.ByLayer
 INSERT -TESTC Lay-0 Scl-1.00,1.00,1.00
 ATTRIB     8.0 62.ByLayer  6.ByLayer
 SEQEND     8.0 62.ByLayer  6.ByLayer
 INSERT -TESTC Lay-0 Scl-1.00,1.00,1.00
 ATTRIB     8.0 62.ByLayer  6.ByLayer
 SEQEND     8.0 62.ByLayer  6.ByLayer

 

BLOCK TEMP1 contains 3 nested inserts. If you change the value of one of the nested insert attributes, all TEMP1 inserts will update.

 

-David

Link to comment
Share on other sites

So I would probably have better luck exploding the block and updating the nested blocks afterwords?

 

Is there a way to tell that the blocks were a part of the original parent block and use that to build a selection set?

Link to comment
Share on other sites

If the insertion block always resides outside of the current drawing, you could use an incremental counter during the insertion

 

Command: INSERT temp2=temp1

 

Command: INSERT temp3=temp1

 

And then redefine each block table immediately after the insertion

 

You cannot use this method if the block is only defined within the current drawing.

 

 

 

As to exploding, I'd try something like:

 

(setq le (entlast)) ;;; record the last entity

(command "_.INSERT" "*TEMP1" '(0 0 0) 1 0)

(setq fe (entnext le)) ;;; the first entity after le

 

 

This will fail if the the insert is the first entity in a drawing

 

The leading * will automatically explode the insert

 

(entmake) ing the whole thing may be a bit complicated but would give you a lot more flexibility

 

 

-David

Link to comment
Share on other sites

You could use something like this to create a Duplicate Definition of the block, then change the attributes within it:

 

;; AddDuplicateDefinition
;; Adds a Duplicate Block Definition
;; Args: Name of existing block to duplicate
;; Returns: VLA Block Object (Definition)

(defun AddDuplicateDefinition ( blockname / blocks block doc ObjLst dupe )
 ;; © Lee Mac  ~  04.06.10
 (vl-load-com)

 (if
   (setq block
     (Itemp
       (setq blocks
         (vla-get-Blocks
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
       blockname
     )
   )
   (progn
     (vlax-for obj block (setq ObjLst (cons obj ObjLst)))
     
     (vla-CopyObjects doc
       (vlax-make-variant
         (vlax-safearray-fill
           (vlax-make-safearray vlax-vbObject
             (cons 0 (1- (length ObjLst)))
           )
           ObjLst
         )
       )
       (setq dupe
         (vla-Add blocks
           (vla-get-origin block)
           (
             (lambda ( # / s )
               (while
                 (Itemp blocks
                   (setq s
                     (strcat blockname
                       (itoa (setq # (1+ #)))
                     )
                   )
                 )
               )
               s
             )
             0
           )
         )
       )
     )
   )
 )
 dupe
)

(defun Itemp ( coll item )
 (if
   (not
     (vl-catch-all-error-p
       (setq item
         (vl-catch-all-apply
           (function vla-item) (list coll item)
         )
       )
     )
   )
   item
 )
)

Link to comment
Share on other sites

Well, you certainly are quite talented with vlisp, and it worked well, but unfortunately the boss doesn't like having multiple instances of the same block per drawing for the purpose of naming. Worried it might affect some external referencing or data extraction that we will be working on down the road.

 

In the meantime, I'm back to exploding the block and updating the individual references.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...