属性块名称修改?
本帖最后由 幸运草 于 2013-4-22 13:13 编辑请问用vb.net如何修改属性块的名称?
如果要更改块名称,则可以这样更改''' <summary>
''' 更改块定义的名称
''' </summary>
''' <param name="OldName">旧名称</param>
''' <param name="NewName">新名称</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function RenameBlockDef(ByVal OldName As String, ByVal NewName As String) As Boolean
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim BlkTable As BlockTable = Trans.GetObject(MyBase.DB.BlockTableId, OpenMode.ForRead)
If BlkTable.Has(OldName) = True AndAlso BlkTable.Has(NewName) = False Then
Dim BlkR As BlockTableRecord = Trans.GetObject(BlkTable.Item(OldName), OpenMode.ForWrite)
BlkR.Name = NewName
RenameBlockDef = True
Else
RenameBlockDef = False
End If
Trans.Commit()
End Using
End Function 如果要修改块参照里的属性,则可以 ''' <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 看见代码就头晕了。
页:
[1]