感觉你VBA 和.net用混了。你可以引用 CAD type library 继续使用VBA方法来创建直线。也可以使用VBA方法,首先引用acmgd.dll acdbmgd.dll 然后代码如下:- Imports Autodesk.AutoCAD.Runtime
- Imports Autodesk.AutoCAD.ApplicationServices
- Imports Autodesk.AutoCAD.DatabaseServices
- Imports Autodesk.AutoCAD.Geometry
-
- <CommandMethod("AddLine")> _
- Public Sub AddLine()
- '' 获得当前文档和数据库 Get the current document and database
- Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
- Dim acCurDb As Database = acDoc.Database
-
- ''启动一个事务 Start a transaction
- Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
-
- '' 以只读方式打开块表 Open the Block table for read
- Dim acBlkTbl As BlockTable
- acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
-
- '' 以写方式打开模型空间块表记录 Open the Block table record Model space for write
- Dim acBlkTblRec As BlockTableRecord
- acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
- OpenMode.ForWrite)
-
- '' 创建一条起点为(5,5,0),终点为(12,3,0)的直线 Create a line that starts at 5,5 and ends at 12,3
- Dim acLine As Line = New Line(New Point3d(5, 5, 0), _
- New Point3d(12, 3, 0))
-
- acLine.SetDatabaseDefaults()
-
- '' 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
- acBlkTblRec.AppendEntity(acLine)
- acTrans.AddNewlyCreatedDBObject(acLine, True)
-
- '' 保存新对象到数据库中 Save the new object to the database
- acTrans.Commit()
- End Using
- End Sub
|