Message 1 of 4
ATTACH XREF VB DotNet

Not applicable
12-31-2009
07:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I would simply attach an external reference in a drawing but my code
does not work.
Is proved yourself where is the mistake?
Thank you for your reply
I wish you all a happy new year
Best regards
Dominic
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Public Class Class1
_
Public Sub XrefInsertion()
Dim NomFichierXref As String = "C:\CERCLE.dwg"
Dim NomXref As String = "CERCLE"
Dim ed As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim db As New Database(True, False)
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
' Attach the Xref
Dim xrefObj As ObjectId = db.AttachXref(NomFichierXref,
NomXref)
' point d'insertion
Dim br As New BlockReference(New Point3d(0, 0, 0), xrefObj)
' Add the xref to model space
Dim bt As BlockTable = trans.GetObject(db.BlockTableId,
OpenMode.ForRead, False)
Dim modelSpace As BlockTableRecord =
trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
modelSpace.AppendEntity(br)
trans.AddNewlyCreatedDBObject(br, True)
trans.Commit()
Catch ex As Exception
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
End Sub
End Class
I would simply attach an external reference in a drawing but my code
does not work.
Is proved yourself where is the mistake?
Thank you for your reply
I wish you all a happy new year
Best regards
Dominic
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Public Class Class1
Public Sub XrefInsertion()
Dim NomFichierXref As String = "C:\CERCLE.dwg"
Dim NomXref As String = "CERCLE"
Dim ed As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim db As New Database(True, False)
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
' Attach the Xref
Dim xrefObj As ObjectId = db.AttachXref(NomFichierXref,
NomXref)
' point d'insertion
Dim br As New BlockReference(New Point3d(0, 0, 0), xrefObj)
' Add the xref to model space
Dim bt As BlockTable = trans.GetObject(db.BlockTableId,
OpenMode.ForRead, False)
Dim modelSpace As BlockTableRecord =
trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
modelSpace.AppendEntity(br)
trans.AddNewlyCreatedDBObject(br, True)
trans.Commit()
Catch ex As Exception
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
End Sub
End Class