Adding attributes to hundreds of blocks

Adding attributes to hundreds of blocks

Designer_1E
Enthusiast Enthusiast
297 Views
3 Replies
Message 1 of 4

Adding attributes to hundreds of blocks

Designer_1E
Enthusiast
Enthusiast

Hello,

(I posted this previously in the wrong forum ‌😬‌)


I need to add the same 7 invisible attributes to hundreds of different blocks, within one drawing. Ideally they would be added to the base point. I am searching for an autoLISP that can do this. Any recommendations?


I have attached a file with the attributes in needed, if you are curious.

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

paullimapa
Mentor
Mentor

Questions:

1) In which dwg are these hundreds of blocks located?

2) What are the names of these blocks?

3) Are the blocks dynamic?

4) Can you share a sample dwg with these blocks?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

There is sample code for add an attribute to an existing block definition. Do a google. Like @paullimapa where is the list of block names for the attributes to be added to and need a dwg to test.

0 Likes
Message 4 of 4

komondormrex
Mentor
Mentor

@Designer_1E 

hey there, 

check the following. adds 7 given attributes to every block in a drawing with syncing. 

(defun c:add_atts nil
  (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
  (setvar 'cmdecho 0)
  (vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    '(lambda (block)
      (and (zerop (vlax-get block 'islayout))
         (zerop (vlax-get block 'isxref))
         (mapcar '(lambda (prompt tag)
              (vla-addattribute block
                        0.001
                        acAttributeModeInvisible
                        prompt
                        (vlax-3d-point 0 0 0)
                        tag
                        ""
              )
              t
              )
             '("Person"    "Department" "Floor"    "Building" "Alias 1"   "Alias 2"   "Alias 3")
             '("CAPPERSON" "CAPDEPT"    "CAPFLOOR" "CAPBLDG"  "CAPALIAS1" "CAPALIAS2" "CAPALIAS3")
         )
         (command "_attsync" "_n" (vla-get-name block))
       )
     )
  )
  (setvar 'cmdecho 1)
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (princ)
)
0 Likes