[求助]雪山飞狐老师请进
我将vb的程序改到了vb.net 但是对于事件的处理出现了问题,它似乎没有反应请老师帮忙给看看Public Class Form1<BR> Inherits System.Windows.Forms.Form<BR> Private WithEvents oDoc As AutoCAD.AcadDocument
Private Sub oDoc_BeginDoubleClick(ByVal PickPoint As Object) Handles oDoc.BeginDoubleClick<BR> Call liancad()<BR> If acadApp Is Nothing Then<BR> MsgBox("无法连接ACAD", vbCritical)
Exit Sub<BR> End If<BR> acadDoc = acadApp.ActiveDocument
'程序处理<BR> MsgBox("asdfasdfaf")<BR> Dim pfSS As AutoCAD.AcadSelectionSet<BR> Dim ssobject As AutoCAD.AcadEntity<BR> Dim msg As String
Dim nodeaddress As Object
Dim xt As Object<BR> Dim xd As Object<BR> Dim i As Integer<BR> node_x = 0 '初始化<BR> node_y = 0<BR> node_z = 0<BR> msg = vbCrLf<BR> pfSS = acadDoc.PickfirstSelectionSet<BR> For Each ssobject In pfSS<BR> msg = msg & vbCrLf & ssobject.ObjectName<BR> If ssobject Is Nothing Then<BR> MsgBox("no")<BR> Exit Sub<BR> End If
If ssobject.ObjectName = "AcDbText" Then
Retpoint = acadDoc.HandleToObject(ssobject.Handle)<BR> ssobject.GetXData("", xt, xd)<BR> For i = 0 To UBound(xt)<BR> Select Case xt(i)<BR> Case 1000
If xd(i) = "node" Then
node_x = Retpoint.InsertionPoint(0)<BR> node_y = Retpoint.InsertionPoint(1)<BR> node_z = Retpoint.InsertionPoint(2)<BR> nodestring = Retpoint.TextString<BR> Else<BR> Exit Sub<BR> End If<BR> End Select<BR> Next i<BR> End If<BR> Next ssobject<BR> Form1.ActiveForm.Hide()<BR> Dim form3 As New zyl3()<BR> form3.ShowDialog()<BR> End Sub acadDoc = acadApp.ActiveDocument应该在事件的外面做,因为acadDoc始终没有实例化,该事件是不会触发的 acadDoc = acadApp.ActiveDocument ,应该做到哪块,比较合适?是在模块中吗?怎么才能触发这个事件呢? 你可以放在窗体的初始化代码,紧接着连接Cad的代码后面 我已经改成了你所说的将
Call liancad()<BR> If acadApp Is Nothing Then<BR> MsgBox("无法连接ACAD", vbCritical)
Exit Sub<BR> End If<BR> acadDoc = acadApp.ActiveDocument
这些代码放到了form_load中了,但是似乎不起作用。是不是声明出错了。 Imports Autodesk.AutoCAD.Interop<BR>Imports Autodesk.AutoCAD.Interop.Common
Public Class Form1<BR> Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()<BR> MyBase.New()
'该调用是 Windows 窗体设计器所必需的。<BR> InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。<BR> Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<BR> If disposing Then<BR> If Not (components Is Nothing) Then<BR> components.Dispose()<BR> End If<BR> End If<BR> MyBase.Dispose(disposing)<BR> End Sub
'Windows 窗体设计器所必需的<BR> Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的<BR> '可以使用 Windows 窗体设计器修改此过程。<BR> '不要使用代码编辑器修改它。<BR> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<BR> '<BR> 'Form1<BR> '<BR> Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)<BR> Me.ClientSize = New System.Drawing.Size(292, 266)<BR> Me.Name = "Form1"<BR> Me.Text = "Form1"
End Sub
#End Region<BR> Private m_oApp As AcadApplication<BR> Private WithEvents m_oDoc As AcadDocument
Private Sub m_oDoc_BeginDoubleClick(ByVal PickPoint As Object) Handles m_oDoc.BeginDoubleClick<BR> m_oApp.Eval("Msgbox 1")<BR> End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> m_oApp = GetObject(, "AutoCad.Application")<BR> m_oDoc = m_oApp.ActiveDocument<BR> End Sub<BR>End Class<BR> 果然是老手
换成vc++解决问题就是麻烦
我改成vb了 vc++还行,现在改学vb才叫麻烦。
不过没有办法,生来笨,只能再学了。
啃vba中
页:
[1]