各位老大:
我的编程环境如下:CAD2004和VB.NET2003
程序如下(请导入CAD的引用):
Public acadApp As AcadApplication Public acadDoc As AcadDocument
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'----------------------------------连接至 AutoCAD 应用程序 Try Cursor.Current = Cursors.WaitCursor acadApp = GetObject(, "AutoCAD.Application.16") Catch ex As Exception acadApp = CreateObject("AutoCAD.Application.16") End Try acadDoc = acadApp.ActiveDocument Application.DoEvents()
Dim lineObj As AcadLine Dim startPt(2) As Double, endPt(2) As Double startPt(0) = 1#: startPt(1) = 1#: startPt(2) = 0# endPt(0) = 5#: endPt(1) = 5#: endPt(2) = 0# Set lineObj = acadDoc .ModelSpace.AddLine(startPt, endPt) Dim DataType(1) As Integer Dim Data(1) As Variant DataType(0) = 1001: Data(0) = "Test_Application" DataType(1) = 1000: Data(1) = "This is a test for xdata" lineObj.SetXData( DataType, Data) End Sub
出现:其他信息: 参数 type (位于 SetXData method 中) 无效的错误,
有用同样的方法在CAD VBA环境下测试,能运行!!
请各位绘予帮助!!谢谢 |