谢谢3楼,问题2中19行 publia class 写成 public Sub 了。 问题1 我第一行就引用了啊 ? Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.Runtime Public Class Class1 ' 创建直线命令 <CommandMethod("FirstLine")> Public Sub TestLine() ' 得到当前文件的数据对象 Dim db As Database = HostApplicationService.WorkingDatabass ' 定义直线对象的起点 Dim pt1 As New Point3d(300, 100, 0) ' 定义直线对象的终点 Dim pt2 As New Point3d(900, 500, 0) ' 在内存中创建一个直线对象 Dim lineEnt As New Line(pt1, pt2) Using Trans As Transaction = db.TransactionManager.StartOpenCloseTransaction() ' 以读方式打开块表 Dim bt As BlockTable = Trans.GetObject(db.BlockTableId, OpenMode.ForRead) ' 以写方式打开模型空间块表记录 Dim btr As BlockTableRecord = Trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite) ' 将图形对象的信息添加到块表中,并返回ObjectId对象 btr.AppendEntity(lineEnt) ' 把直线添加到事务处理中 Trans.AddNewlyCreatedDBObject(lineEnt, True) ' 提交事务处理 Trans.Commit() End Using
End Sub End Class
|