Xref
I am having a code which is working in AutoCAD to remove and attach X-ref without opening the dwg file.
but this coding is not working in BricsCAD.
Please Help......\
#Region "RemoveAllXRef" Private Sub RemoveAllXRef(ByVal xRefPath, ByVal HostPath) Using xrefDb As Database = New Database(False, True) xrefDb.ReadDwgFile(HostPath, FileShare.ReadWrite, True, "") 'Remove XRef' Using trans As Transaction = xrefDb.TransactionManager.StartTransaction() Dim bt As BlockTable = trans.GetObject(xrefDb.BlockTableId, OpenMode.ForWrite) 'Now remove the XRef of deleted property from db' Dim XRefIDsToChange As ObjectIdCollection = New ObjectIdCollection For Each btrId As ObjectId In bt Dim btr As BlockTableRecord = trans.GetObject(btrId, OpenMode.ForWrite) If btr.IsFromExternalReference Then XRefIDsToChange.Add(btrId) xrefDb.DetachXref(btrId) End If Next xrefDb.CloseInput(True) xrefDb.SaveAs(HostPath, DwgVersion.AC1024) trans.Commit() End Using End Using End Sub
#Region "AddXRef" Private Sub AddXRef(ByVal xRefPath As String, ByVal HostPath As String) Using xrefDb As Database = New Database(False, True) xrefDb.ReadDwgFile(HostPath, FileShare.ReadWrite, True, "") 'Add XRef' Using trx As Transaction = xrefDb.TransactionManager.StartTransaction() Dim xrefBt As BlockTable = xrefDb.BlockTableId.GetObject(OpenMode.ForWrite) Dim btrMs As BlockTableRecord = xrefBt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite) Dim xrefObjId As ObjectId = xrefDb.OverlayXref(xRefPath, Path.GetFileNameWithoutExtension(xRefPath)) Dim bref As New BlockReference(Point3d.Origin, xrefObjId) btrMs.AppendEntity(bref) trx.AddNewlyCreatedDBObject(bref, True) xrefDb.CloseInput(True) xrefDb.SaveAs(HostPath, DwgVersion.AC1024) trx.Commit() End Using End Using End Sub