明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1462|回复: 7

[求助]雪山飞狐老师请进

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


换成vc++解决问题就是麻烦


我改成vb了
发表于 2004-11-30 20:00:00 | 显示全部楼层
vc++还行,现在改学vb才叫麻烦。


不过没有办法,生来笨,只能再学了。


啃vba中
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 23:42 , Processed in 0.179276 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表