How do you reload xrefs with vb.net?
I haven't done any work with xrefs in code..
Solved! Go to Solution.
Nvm. Found a solution.
Public Sub ReloadXRefs()
Dim doc As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ids As New ObjectIdCollection()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim table As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
For Each id As ObjectId In table
Dim record As BlockTableRecord = TryCast(tr.GetObject(id, OpenMode.ForRead), BlockTableRecord)
If record.IsFromExternalReference Then
ids.Add(id)
End If
Next
tr.Commit()
End Using
'now relaod the xrefs
If Not ids.Count = 0 Then
db.ReloadXrefs(ids)
End If
End Sub
Another option to iterating the entire block table, is to use the XrefGraph:
Sub ReloadXrefsy(ByRef myDWG As Document)
Dim myDB As Database = myDWG.Database
Dim myED As Editor = myDWG.Editor
Dim XrefIDS As New ObjectIdCollection
Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
Dim xg As XrefGraph = myDB.GetHostDwgXrefGraph(False)
For i As Integer = 0 To xg.NumNodes - 1
Dim xgn As XrefGraphNode = xg.GetXrefNode(i)
If xgn.BlockTableRecordId.IsValid Then
XrefIDS.Add(xgn.BlockTableRecordId)
End If
Next
If XrefIDS.Count > 0 Then
myDB.ReloadXrefs(XrefIDS)
End If
myTrans.Commit()
End Using
myED.WriteMessage(vbLf & "Reloaded " & XrefIDS.Count.ToString & " xrefs.")
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.