外部参照绑定和拆除
'绑定外部参照
<CommandMethod("BindXrefs")> _
Public Sub BindXrefs()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = CType(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
For Each id As ObjectId In bt
Dim btr As BlockTableRecord = CType(id.GetObject(OpenMode.ForRead), BlockTableRecord)
'MsgBox(btr.XrefStatus.ToString)
'NotAnXref
'FileNotFound
'Resolved
If btr.XrefStatus <> XrefStatus.NotAnXref AndAlso btr.XrefStatus <> XrefStatus.FileNotFound Then
'db.DetachXref(id)
Dim IDC As ObjectIdCollection = New ObjectIdCollection
IDC.Add(id)
db.BindXrefs(IDC, False)
End If
Next
tr.Commit()
End Using
End Sub
'拆除外部参照
<CommandMethod("DetachXrefs")> _
Public Sub DetachXrefs()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = CType(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
For Each id As ObjectId In bt
Dim btr As BlockTableRecord = CType(id.GetObject(OpenMode.ForRead), BlockTableRecord)
'MsgBox(btr.XrefStatus.ToString)
'NotAnXref
'FileNotFound
'Resolved
If btr.XrefStatus <> XrefStatus.NotAnXref AndAlso btr.XrefStatus <> XrefStatus.Resolved Then
db.DetachXref(id)
'Dim IDC As ObjectIdCollection = New ObjectIdCollection
'IDC.Add(id)
'db.BindXrefs(IDC, False)
End If
Next
tr.Commit()
End Using
End Sub
梁编号归并
欢迎关注微信公众账号ByCAD