Quantcast
Channel: Autodesk AutoCAD forums
Viewing all articles
Browse latest Browse all 14319

Insert new istances of already defined X-Ref

$
0
0

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

 


Viewing all articles
Browse latest Browse all 14319

Trending Articles