.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

reload all xrefs

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
810 Views, 2 Replies

reload all xrefs

How do you reload xrefs with vb.net?

 

I haven't done any work with xrefs in code..

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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

Message 3 of 3
elliottpd11
in reply to: Anonymous

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost