Hi,
I'm trying to insert a new istance of a X-Ref already present on the drawing. If i use Database.AttachXref(path, name) I receive "ref NAME has already been defined. Using existing definition." on the command bar. I've tried to retrieve the ObjectId of the X-Ref definition from the X-Ref name, but my code don't work. Where is the error?
Thank you
Here's my code:
Private Sub AttachXRef(path As String, name As String) Dim Doc As Document = Application.DocumentManager.MdiActiveDocument Dim Db As Database = Doc.Database Dim pPtRes As PromptPointResult Dim pPtOpts As PromptPointOptions = New PromptPointOptions("") pPtOpts.Message = vbLf & "Seleziona punto di inserimento: " pPtRes = Doc.Editor.GetPoint(pPtOpts) Dim Pt As Point3d = pPtRes.Value Dim Tr As Transaction = Doc.TransactionManager.StartTransaction() Dim LockDoc As DocumentLock = Doc.LockDocument() Using LockDoc Using Tr Dim xrefObj As ObjectId = Db.AttachXref(path, name) Dim Br As New BlockReference(Pt, xrefObj) Dim Bt As BlockTable = Tr.GetObject(Db.BlockTableId, OpenMode.ForRead) Dim BtModel As BlockTableRecord = Tr.GetObject(Bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) BtModel.AppendEntity(Br) Tr.AddNewlyCreatedDBObject(Br, True) Tr.Commit() End Using End Using End Sub Private Sub InsertXRef(name As String) Dim Doc As Document = Application.DocumentManager.MdiActiveDocument Dim Db As Database = Doc.Database Dim pPtRes As PromptPointResult Dim pPtOpts As PromptPointOptions = New PromptPointOptions("") pPtOpts.Message = vbLf & "Seleziona punto di inserimento: " pPtRes = Doc.Editor.GetPoint(pPtOpts) Dim Pt As Point3d = pPtRes.Value Dim Tr As Transaction = Doc.TransactionManager.StartTransaction() Dim LockDoc As DocumentLock = Doc.LockDocument() Using LockDoc Using Tr Dim Bt As BlockTable = DirectCast(Tr.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable) Dim BtRecId As ObjectId = Bt(name) Dim Br As New BlockReference(Pt, BtRecId) Dim BtModel As BlockTableRecord = TryCast(Tr.GetObject(Bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) BtModel.AppendEntity(Br) Tr.AddNewlyCreatedDBObject(Br, True) Tr.Commit() End Using End Using End Sub
Hi Dario,
I do not see any problem with your code.
When I call those methods as :
AttachXRef("C:\Temp\Test.dwg", "MyTest")
InsertXRef("MyTest")
It creates a Xref and creates another instance of the same XRef.
Can you please let me know the steps to reproduce the error that you are getting ?
How are you using those two methods ?
Today i've tested again the code for replicate the error but now it seem to work.
Previously the code didn't create any exception, but also didn't draw the block reference in the drawing at the end of InsertXRef Sub.