Attach xref

stefano.cartaKGT96
Advocate
Advocate

Attach xref

stefano.cartaKGT96
Advocate
Advocate

Hi guys..

I use this code for open in memory a dwg and attach an xref to it and save the dwg.

when I open the dwg with Autocad I can view the attached xref in the xref palette, but I can't view it in the drawing.

 

what am I doing wrong?

Dim xrefDb As Database = New Database(False, True)
                xrefDb.ReadDwgFile(Item.ToString, FileShare.ReadWrite, False, "")

                Using trx As Transaction = xrefDb.TransactionManager.StartTransaction()

                    Dim xrefBt As BlockTable = xrefDb.BlockTableId.GetObject(OpenMode.ForRead)
                    Dim btrMs As BlockTableRecord = xrefBt(BlockTableRecord.PaperSpace).GetObject(OpenMode.ForWrite)

                    Dim xrefObjId As ObjectId = xrefDb.AttachXref(NomeFileCart, Path.GetFileNameWithoutExtension(NomeFileCart))

                    Dim bref As New BlockReference(Point3d.Origin, xrefObjId)

                    btrMs.AppendEntity(bref)
                    trx.AddNewlyCreatedDBObject(bref, True)

                    xrefDb.CloseInput(True)
                    xrefDb.SaveAs(Item.ToString, DwgVersion.Current)

                    trx.Commit()

                End Using
                xrefDb.SaveAs(Item.ToString, DwgVersion.AC1032)
0 Likes
Reply
Accepted solutions (1)
309 Views
3 Replies
Replies (3)

_gile
Mentor
Mentor

Hi,

Why do save the database twice?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

stefano.cartaKGT96
Advocate
Advocate

HI....

I didn't notice the double SAVE thanks..

 

 

0 Likes

stefano.cartaKGT96
Advocate
Advocate
Accepted solution

I found the problem .... the xref file only had objects in the paperspace ...

0 Likes