Message 1 of 14
Bind Xrefs
Not applicable
12-24-2007
01:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi to all. I have'nt seen a lot on xrefs bind. So I've done an effort on my side and wanted to share this code with you. It's a basic Bind Command. You can send me your comments if you wish!
Don't forget to put the < before the commandmethod!!!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
CommandMethod("BindAllXrefs")> _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
'Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
'Check if block is xref and add if so, add it's ID to the ObjectIdCollection
If bBTR.IsResolved And Not bBTR.Name.Contains("|") Then
XrefIds.Add(bBTR.Id)
End If
End While
'Bind xref of collection
bDwg.Database.BindXrefs(XrefIds, True)
'Important to commit
bTrans.Commit()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub
Don't forget to put the < before the commandmethod!!!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
CommandMethod("BindAllXrefs")> _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
'Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
'Check if block is xref and add if so, add it's ID to the ObjectIdCollection
If bBTR.IsResolved And Not bBTR.Name.Contains("|") Then
XrefIds.Add(bBTR.Id)
End If
End While
'Bind xref of collection
bDwg.Database.BindXrefs(XrefIds, True)
'Important to commit
bTrans.Commit()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub