如果要修改块参照里的属性,则可以- ''' <summary>
- ''' 更改块中属性名称
- ''' </summary>
- ''' <param name="IDs">块参照ID</param>
- ''' <param name="OldAttName">旧名称</param>
- ''' <param name="NewAttName">新名称</param>
- ''' <param name="RenameAll">遇到多个同名AttName,如果RenameAll = True ,则全部重新命名,否则 改第一个</param>
- ''' <returns>修改成功返回 True ,不成功则返回 False</returns>
- ''' <remarks></remarks>
- Public Function ReNameAtt(ByVal IDs() As ObjectId, ByVal OldAttName As String, ByVal NewAttName As String, Optional ByVal RenameAll As Boolean = True) As Boolean()
- Dim rtn(IDs.Length - 1) As Boolean
- OldAttName = OldAttName.Trim.ToUpper : NewAttName = NewAttName.Trim.ToUpper
- Using Trans As Transaction = DB.TransactionManager.StartTransaction
- Dim obj As DBObject = Nothing, blk As BlockReference = Nothing, Atts As AttributeCollection = Nothing,Att As AttributeReference = Nothing
- For I As Integer = 0 To IDs.Length - 1
- obj = Trans.GetObject(IDs(I), OpenMode.ForWrite)
- If TypeOf obj Is BlockReference Then
- blk = obj
- Atts = blk.AttributeCollection
- For J As Integer = 0 To Atts.Count - 1
- Att = Trans.GetObject(Atts(J), OpenMode.ForWrite)
- If Att.Tag.ToUpper = OldAttName Then
- Att.Tag = NewAttName
- If RenameAll = False Then
- Continue For
- End If
- End If
- Next
- rtn(I) = True
- End If
- Next
- Trans.Commit()
- End Using
- ReNameAtt = rtn
- End Function
|