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

Insert new istances of already defined X-Ref

2 REPLIES 2
Reply
Message 1 of 3
Dario.Esain
492 Views, 2 Replies

Insert new istances of already defined X-Ref

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

 

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: Dario.Esain

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 ?



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
Dario.Esain
in reply to: Balaji_Ram

 

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.

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