vb2005在cad中的问题
大侠们帮我看看,下面代码的最后一行错了,知怎么更正。Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication
Dim acaddoc As HtmlDocument
On Error Resume Next
acadapp = GetObject(, "AutoCAD.Application") '连接到CAD应用软件
If Err.Number Then
Err.Clear()
acadapp = CreateObject("AutoCAD.Application") '创建CAD对象
If Err.Number Then
MsgBox("请检查是否安装了CAD!")
Exit Sub
End If
End If
acadapp.Visible = True
acaddoc = acadapp.ActiveDocument '设置CAD为活动文档
Dim lineobj As AcadLine '绘制断面图
Dim arcobj As AcadArc
Dim shuhao, total As Integer
Dim yxx, yxy, r, barc, earc, lx, Radius, startangle, endangle, weiyan As Double
Dim startpoint(0 To 2) As Double
Dim endpoint(0 To 2) As Double
Dim centerpoint(0 To 2) As Double
Dim arc As String
weiyan = Val(TextBox8.Text) '衬砌厚度
Dim shuhao3 As Integer
Dim qdzh, zdzh, qddmg, zddmg, h4, k As Double
lineobj = acaddoc.ModelSpace.AddLine(startpoint, endpoint
题示:ModelSpace不是system.windows.forms.HTMLdocument的成员
我该怎么做呢?
感觉你VBA 和.net用混了。你可以引用 CADtype library 继续使用VBA方法来创建直线。也可以使用VBA方法,首先引用acmgd.dllacdbmgd.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
楼上的大哥,能不能给个VBA的示例,我以前用VB6编过,现在换成.NET就不懂怎么办了。 我现在是CAD能打开,就是直线绘制不出来
1, Dim acaddoc As HtmlDocument 应该 是AcadDocument
2, 你的问题在 VBA/VB/ActiveX/API 编程技术 版块更好些。 VB6是VB,VB2005是vb.net,不清楚你到底要用什么编辑器。VBA是CAD自带的编译器,语法同VB6。代码漫天都是。下面是VBA里面添加线的代码,如果用VB6稍作修改就行了。Sub Example_AddLine()
' 该示例在模型空间中添加直线。
Dim lineObj As AcadLine
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double
' 定义直线的起点和终点
startPoint(0) = 1#: startPoint(1) = 1#: startPoint(2) = 0#
endPoint(0) = 5#: endPoint(1) = 5#: endPoint(2) = 0#
' 在模型空间中创建直线
Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
ZoomAll
End Sub
页:
[1]