[求助]Auto CAD VBA&VB.Net开发基础与实例教程 例题问题请教
<p>刚接触VB.net,跟着书本例题写,碰到2个问题:VS2005 + autocad2010</p><p>1:书290页:Dim db As Database = HostApplicationService.WorkingDatabass </p><p> 提示:未声明名称 HostApplicationService ?</p><p>2:书280页,最后两行输入后</p><p> 提示:语句在命名空间中无效 ?</p><p></p><p></p> 1、引用Autodesk.AutoCAD.DatabaseServices2、Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationSerVices
Imports Autodesk.AutoCAD.EditorInput
<Assembly: ExtensionApplication(GetType(ManagedApp.Init))>
<Assembly: CommandClass(GetType(ManagedApp.Commands))>
Namespace ManagedApp
Public Class Init
Implements IExtensionApplication
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
' 在AutoCAD命令行上显示一些信息,它们会在程序载入时被显示
ed.WriteMessage("程序开始初始化")
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
' 在 VisualStudio 2005的输出窗口上显示程序结束的信息
Debug.WriteLine("程序结束,你可以在这里做一些清理工作,如关闭AutoCAD文档")
End Sub
End Class
Public Class Commands
<CommandMethod("LoadAssembly")> _
Public Sub LoadAssembly()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'Hello.dll程序的文件名
Dim fileName As String = "I:/vb.net/Hello/hello.dll"
' 载入 Hello.dll程序集
ExtensionLoader.Load(fileName)
' 在命令行上显示信息,提示用户 Hello.dll程序集已经被载入
ed.WriteMessage(vbCrLf & fileName & "被载入,请输入Hello进行测试!")
End Sub
End Class
End Namespace
<p>谢谢3楼,问题2中19行 publia class 写成 public Sub 了。</p><p>问题1 我第一行就引用了啊 ?</p><p></p><p>Imports Autodesk.AutoCAD.DatabaseServices<br/>Imports Autodesk.AutoCAD.Geometry<br/>Imports Autodesk.AutoCAD.Runtime<br/>Public Class Class1<br/> ' 创建直线命令<br/> <CommandMethod("FirstLine")> Public Sub TestLine()<br/> ' 得到当前文件的数据对象<br/> Dim db As Database = HostApplicationService.WorkingDatabass<br/> ' 定义直线对象的起点<br/> Dim pt1 As New Point3d(300, 100, 0)<br/> ' 定义直线对象的终点<br/> Dim pt2 As New Point3d(900, 500, 0)<br/> ' 在内存中创建一个直线对象<br/> Dim lineEnt As New Line(pt1, pt2)<br/> Using Trans As Transaction = db.TransactionManager.StartOpenCloseTransaction()<br/> ' 以读方式打开块表<br/> Dim bt As BlockTable = Trans.GetObject(db.BlockTableId, OpenMode.ForRead)<br/> ' 以写方式打开模型空间块表记录<br/> Dim btr As BlockTableRecord = Trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)<br/> ' 将图形对象的信息添加到块表中,并返回ObjectId对象<br/> btr.AppendEntity(lineEnt)<br/> ' 把直线添加到事务处理中<br/> Trans.AddNewlyCreatedDBObject(lineEnt, True)<br/> ' 提交事务处理<br/> Trans.Commit()</p><p><br/> End Using</p><p> End Sub<br/>End Class<br/></p> <div style="PADDING-RIGHT: 0px; MARGIN-TOP: 10px; FONT-SIZE: 12pt; OVERFLOW-X: hidden; WIDTH: 97%; WORD-BREAK: break-all; TEXT-INDENT: 0px; LINE-HEIGHT: normal; HEIGHT: 200px; WORD-WRAP: break-word;">好啊好啊,谢谢</div>
页:
[1]