I tried to translate Gabriels C code to VB from here:
http://www.theswamp.org/index.php?topic=31863.0I only needed a little bit of it, so below is what I tried:
The problem is when I get to "xREF = Trans.GetObject(xrefID, OpenMode.ForRead)" I get an error saying it can't convert MText object to an external reference object.
I don't understand how an MText object is getting past XrefStatus.Resoved.
I also don't understand...maybe I just answered my own question.
Is the "xREF = Trans.GetObject(xrefID, OpenMode.ForRead)" jumping back over the BTR.XrefStatus and retrieving the parent object ?
Oi... :ugly:
Dim Doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim CurDb As Database = Doc.Database
Dim xREF As AcadExternalReference = Nothing
Dim xrefID As ObjectId = ObjectId.Null
Using Trans As Transaction = CurDb.TransactionManager.StartTransaction
Dim BT As BlockTable = Trans.GetObject(CurDb.BlockTableId, OpenMode.ForRead)
For Each ObjID As ObjectId In BT
Dim BTR As BlockTableRecord = Trans.GetObject(ObjID, OpenMode.ForRead)
If BTR.IsFromExternalReference Then
If BTR.XrefStatus = XrefStatus.Resolved Then
Dim XrefCol As New ObjectIdCollection
For Each xrefID In BTR
xREF = Trans.GetObject(xrefID, OpenMode.ForRead)
If xREF.Name = "SK1-IR" And xREF.Visible Then
XrefCol.Add(xrefID)
CurDb.UnloadXrefs(XrefCol)
ElseIf xREF.Name = "SK1-IR" And Not xREF.Visible Then
XrefCol.Add(xrefID)
CurDb.ReloadXrefs(XrefCol)
End If
Next
End If
End If
Next
End Using