Author Topic: How do replace an attribute in a table?  (Read 1321 times)

0 Members and 1 Guest are viewing this topic.

Refri

  • Mosquito
  • Posts: 11
How do replace an attribute in a table?
« on: April 13, 2017, 08:03:59 AM »
How do replace an attribute in a table?
There is a table.
It contains a block with an attribute.
It is necessary through VBA in the first line of the table to change the attribute "ATR" value "DD25" to "HH38".
I'm trying to get a block and change the attribute, but it changes it for everyone.

Code: [Select]
Set block = ThisDrawing.Blocks
For Each item In block
str = item.EntityName
 'Get t attributes
If item.EntityName = "AcDbAttributeDefinition" Then
if item.TextString ="DD25" then  item.TextString="HH38"
End If
End If
Next item

DEVITG

  • Bull Frog
  • Posts: 430
Re: How do replace an attribute in a table?
« Reply #1 on: April 18, 2017, 05:26:40 PM »
Hi, I   know almost nothing about VBA , but what you have to change ia at BLOCKREFERENCE , not at the BLOCKCOLLECTION . I do Lisp.
If you look for BLOCKCOLLECTION , of course all will be changed .
Hope it help 
Location @ Córdoba Argentina Using ACAD 2019  at Window 7

Refri

  • Mosquito
  • Posts: 11
Re: How do replace an attribute in a table?
« Reply #2 on: April 19, 2017, 02:28:00 AM »
Problem is that these blocks do not exist in the BLOCKREFERENCE.
If there is an example of a lisp - give

roy_043

  • Water Moccasin
  • Posts: 1759
  • BricsCAD 18
Re: How do replace an attribute in a table?
« Reply #3 on: April 19, 2017, 09:01:59 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test ( / attDefId blk blkRecId enm tbl)
  2.   (if
  3.     (and
  4.       (setq enm (car (entsel)))
  5.       (setq tbl (vlax-ename->vla-object enm))
  6.       (= "AcDbTable" (vla-get-objectname tbl))
  7.       (/= 0 (setq blkRecId (vla-getblocktablerecordid tbl 0 0)))
  8.     )
  9.     (progn
  10.       (vlax-for obj blk
  11.         (if
  12.           (and
  13.             (not attDefId)
  14.             (= "AcDbAttributeDefinition" (vla-get-objectname obj))
  15.           )
  16.           (setq attDefId (vla-get-objectid obj))
  17.         )
  18.       )
  19.       (if attDefId
  20.         (vla-setblockattributevalue tbl 0 0 attDefId "New String")
  21.       )
  22.     )
  23.   )
  24.   (princ)
  25. )

Refri

  • Mosquito
  • Posts: 11
Re: How do replace an attribute in a table?
« Reply #4 on: April 20, 2017, 12:04:13 AM »
roy_043
Excellent !
Thank you ! Exactly what is needed. The question is solved.