How to import libraries into "Visual Basic for Applications"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I'm new into AutoCAD programming (I'm used to developing Revit Apps through the API) but now my company needs to update some old VB routines (made to work in AutoCAD 2012) in AutoCAD 2018.
I found this thread (quite old), and I'm trying to replicate the explained procedure in the "Visual Basic for Applications" Editor that comes with AutoCAD 2018 (Tools>Macro>Visual Basic Editor).
https://forums.autodesk.com/t5/net/enodatabase-with-inserting-a-block-c/td-p/4653083
Example Code:
<CommandMethod("IBLK")> Public Sub InsertBLockfromOutside() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim blockname As String = "TestBLK" Dim drawingPath As String = "C:\Users\alamzaki\Desktop\Test_data\PG-VSON-4-1_afattintel_test.dwg" Dim blkPos As Point3d = New Point3d(0, 0, 0) Try Using tx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead) Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) If Not bt.Has(blockname) Then InsertBlock(blockname, drawingPath, blkPos, db, ms, tx) End If tx.Commit() End Using Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub Public Sub InsertBlock(blkName As String, dwgPath As String, positon As Point3d, acDb As Database, btr As BlockTableRecord, trans As Transaction) Dim dbdwg As Database = New Database(False, True) dbdwg.ReadDwgFile(dwgPath, FileOpenMode.OpenForReadAndAllShare, True, "") Dim id As ObjectId = acDb.Insert(blkName, dbdwg, True) dbdwg.Dispose() Dim blkRef As New BlockReference(positon, id) btr.AppendEntity(blkRef) trans.AddNewlyCreatedDBObject(blkRef, True) End Sub
The methods created calls some objects that I cannot find (i.e. Database, Point3d, Transaction, etc.) and don't really know where to add a library (my intuition is that if I'm working directly into AutoCAD I don't really need to call for a library - API, right?)
So, what am I missing here? Any tip of advice will be well received.
Thanks in advance!