chxiao 发表于 2009-8-16 17:35:00

[求助]Auto CAD VBA&VB.Net开发基础与实例教程 例题问题请教

<p>刚接触VB.net,跟着书本例题写,碰到2个问题:VS2005 + autocad2010</p><p>1:书290页:Dim db As Database = HostApplicationService.WorkingDatabass&nbsp; </p><p>&nbsp;&nbsp; 提示:未声明名称 HostApplicationService&nbsp; ?</p><p>2:书280页,最后两行输入后</p><p>&nbsp; 提示:语句在命名空间中无效&nbsp;&nbsp; ?</p><p></p><p></p>

chxiao 发表于 2009-8-16 17:36:00

雪山飞狐_lzh 发表于 2009-8-16 18:04:00

1、引用Autodesk.AutoCAD.DatabaseServices
2、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

chxiao 发表于 2009-8-20 13:57:00

<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/>&nbsp;&nbsp;&nbsp; ' 创建直线命令<br/>&nbsp;&nbsp;&nbsp; &lt;CommandMethod("FirstLine")&gt; Public Sub TestLine()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 得到当前文件的数据对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim db As Database = HostApplicationService.WorkingDatabass<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 定义直线对象的起点<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim pt1 As New Point3d(300, 100, 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 定义直线对象的终点<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim pt2 As New Point3d(900, 500, 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 在内存中创建一个直线对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lineEnt As New Line(pt1, pt2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using Trans As Transaction = db.TransactionManager.StartOpenCloseTransaction()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 以读方式打开块表<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bt As BlockTable = Trans.GetObject(db.BlockTableId, OpenMode.ForRead)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 以写方式打开模型空间块表记录<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim btr As BlockTableRecord = Trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 将图形对象的信息添加到块表中,并返回ObjectId对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; btr.AppendEntity(lineEnt)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 把直线添加到事务处理中<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trans.AddNewlyCreatedDBObject(lineEnt, True)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 提交事务处理<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trans.Commit()</p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using</p><p>&nbsp;&nbsp;&nbsp; End Sub<br/>End Class<br/></p>

tomcom 发表于 2009-8-26 10:16:00

<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]
查看完整版本: [求助]Auto CAD VBA&VB.Net开发基础与实例教程 例题问题请教