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

ATTACH XREF VB DotNet

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
1379 Views, 3 Replies

ATTACH XREF VB DotNet

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
3 REPLIES 3
Message 2 of 4
Hallex
in reply to: Anonymous

Try edited version

{code}
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class Class1
_
Public Sub XrefInsertion()
Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument

Dim NomFichierXref As String = "C:\CERCLE.dwg"

Dim NomXref As String = "CERCLE"

Dim ed As Editor = doc.Editor()

Dim db As Database = doc.Database

Dim trans As Transaction = db.TransactionManager.StartTransaction()

Using (trans)

Try

Dim xrefObj As ObjectId = db.AttachXref(NomFichierXref, NomXref)
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim modelSpace As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)

Dim btr As BlockTableRecord = CType(trans.GetObject(xrefObj, OpenMode.ForWrite), BlockTableRecord)

Dim br As BlockReference = New BlockReference(New Point3d(0, 0, 0), xrefObj)


modelSpace.AppendEntity(br)

trans.AddNewlyCreatedDBObject(br, True)

trans.Commit()


Catch ex As Autodesk.AutoCAD.Runtime.Exception

MsgBox(ex.Message & vbLf & ex.StackTrace)

End Try

End Using

End Sub


End Class
{code}

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4
Anonymous
in reply to: Anonymous

Super

happy new year

Dominic

hallex a écrit :
> Try edited version
>
> {code}
> Imports Autodesk.AutoCAD.Runtime
> Imports Autodesk.AutoCAD.ApplicationServices
> Imports Autodesk.AutoCAD.DatabaseServices
> Imports Autodesk.AutoCAD.Geometry
> Imports Autodesk.AutoCAD.EditorInput
> Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
>
> Public Class Class1
> _
> Public Sub XrefInsertion()
> Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
>
> Dim NomFichierXref As String = "C:\CERCLE.dwg"
>
> Dim NomXref As String = "CERCLE"
>
> Dim ed As Editor = doc.Editor()
>
> Dim db As Database = doc.Database
>
> Dim trans As Transaction = db.TransactionManager.StartTransaction()
>
> Using (trans)
>
> Try
>
> Dim xrefObj As ObjectId = db.AttachXref(NomFichierXref, NomXref)
> Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead, False)
> Dim modelSpace As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
>
> Dim btr As BlockTableRecord = CType(trans.GetObject(xrefObj, OpenMode.ForWrite), BlockTableRecord)
>
> Dim br As BlockReference = New BlockReference(New Point3d(0, 0, 0), xrefObj)
>
>
> modelSpace.AppendEntity(br)
>
> trans.AddNewlyCreatedDBObject(br, True)
>
> trans.Commit()
>
>
> Catch ex As Autodesk.AutoCAD.Runtime.Exception
>
> MsgBox(ex.Message & vbLf & ex.StackTrace)
>
> End Try
>
> End Using
>
> End Sub
>
>
> End Class
> {code}
>
> ~'J'~
Message 4 of 4
Hallex
in reply to: Anonymous

Happy New Year Dominique

Cheers,

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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