TheSwamp

Code Red => VB(A) => Topic started by: Refri on April 13, 2017, 08:03:59 AM

Title: How do replace an attribute in a table?
Post by: Refri 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
Title: Re: How do replace an attribute in a table?
Post by: DEVITG 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 
Title: Re: How do replace an attribute in a table?
Post by: Refri 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
Title: Re: How do replace an attribute in a table?
Post by: roy_043 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. )
Title: Re: How do replace an attribute in a table?
Post by: Refri on April 20, 2017, 12:04:13 AM
roy_043
Excellent !
Thank you ! Exactly what is needed. The question is solved.