Detach XRefs

Detach XRefs

gwhitcherQ98HZ
Enthusiast Enthusiast
362 Views
2 Replies
Message 1 of 3

Detach XRefs

gwhitcherQ98HZ
Enthusiast
Enthusiast

I have been trying to detach the Xrefs in a list of drawings and had no success.  I open each one then I use this code. It does hit the db.detachXref(oid) line. No errors but does not detach it.

 

 doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                ed = doc.Editor
                db = doc.Database
                Using lk As DocumentLock = doc.LockDocument()
                    Using tr As Transaction = db.TransactionManager.StartTransaction()
                        Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                        For Each oid As ObjectId In bt
                            Dim btr As BlockTableRecord = CType(tr.GetObject(oid, OpenMode.ForRead), BlockTableRecord)
                            If btr.IsFromExternalReference Then
                                db.DetachXref(oid)
                            End If
                        Next
                    End Using
                End Using

 

0 Likes
Accepted solutions (1)
363 Views
2 Replies
Replies (2)
Message 2 of 3

fieldguy
Advisor
Advisor
Accepted solution

you are missing tr.Commit() before end using

0 Likes
Message 3 of 3

gwhitcherQ98HZ
Enthusiast
Enthusiast

How did I miss that! Thank you!

0 Likes