.NET

Reply
New Member
Dario.Esain
Posts: 2
Registered: ‎09-06-2013
Message 1 of 3 (214 Views)

Insert new istances of already defined X-Ref

214 Views, 2 Replies
09-06-2013 01:11 AM

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

 

ADN Support Specialist
Balaji_Ram
Posts: 701
Registered: ‎03-21-2011
Message 2 of 3 (143 Views)

Re: Insert new istances of already defined X-Ref

09-11-2013 05:48 AM 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

New Member
Dario.Esain
Posts: 2
Registered: ‎09-06-2013
Message 3 of 3 (130 Views)

Re: Insert new istances of already defined X-Ref

09-11-2013 06:57 AM 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.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.