关于CAD VBA二次开发 循环 与判定函数
如图;点击计算面积窗口消失,点击CAD中封闭图形区域得到面积,并将结果显示到文本框中。问题:如何实现在选择多个封闭区域后,按enter显示窗口,并将选择的多个封闭区域面积...
如图;点击计算面积窗口消失,点击CAD 中封闭图形区域得到面积,并将结果显示到文本框中。
问题:如何实现在选择多个 封闭区域后,按enter 显示窗口,并将选择的多个封闭区域面积累加,显示在文本框中。 关键是如何实现获取键盘 enter 后显示 窗口,用什么函数,先谢谢高手指点
以下是按钮[计算面积]代码
Private Sub CommandButton1_Click()
'当前图样的实体数目
Dim n As Long
n = ThisDrawing.ModelSpace.Count
Dim pt As Variant
'将控制权交给CAD
UserForm1.Hide
'获取点的位置
pt = ThisDrawing.Utility.GetPoint(, "指定内部点:")
ThisDrawing.SendCommand "-Boundary" & vbCr & pt(0) & "," & pt(1) & vbCr & vbCr
'如果存在边界,则会生成新的实体
Dim objpoly As AcadLWPolyline
If ThisDrawing.ModelSpace.Count > n Then
Set objpoly = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
'为文本框添加面积值
TextBox1.Text = objpoly.Area
UserForm1.Show
Else
MsgBox "未发现有效的边界。"
End If
End Sub 展开
问题:如何实现在选择多个 封闭区域后,按enter 显示窗口,并将选择的多个封闭区域面积累加,显示在文本框中。 关键是如何实现获取键盘 enter 后显示 窗口,用什么函数,先谢谢高手指点
以下是按钮[计算面积]代码
Private Sub CommandButton1_Click()
'当前图样的实体数目
Dim n As Long
n = ThisDrawing.ModelSpace.Count
Dim pt As Variant
'将控制权交给CAD
UserForm1.Hide
'获取点的位置
pt = ThisDrawing.Utility.GetPoint(, "指定内部点:")
ThisDrawing.SendCommand "-Boundary" & vbCr & pt(0) & "," & pt(1) & vbCr & vbCr
'如果存在边界,则会生成新的实体
Dim objpoly As AcadLWPolyline
If ThisDrawing.ModelSpace.Count > n Then
Set objpoly = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
'为文本框添加面积值
TextBox1.Text = objpoly.Area
UserForm1.Show
Else
MsgBox "未发现有效的边界。"
End If
End Sub 展开
1个回答
展开全部
'声明函数
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'判断 enter按下
do while
'获取面积,累加
If GetAsyncKeyState(13) = -32767 Then
'enter按下,显示面积
UserForm1.Show
exit do '退出循环
End If
loop
'具体程序如下,已调试通过
'添加模块1
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'窗体代码
Private Sub CommandButton1_Click()
'当前图样的实体数目
Dim n As Long
n = ThisDrawing.ModelSpace.Count
Dim pt As Variant
Dim objpoly As AcadLWPolyline
'将控制权交给CAD
UserForm1.Hide
Do While True
'获取点的位置
pt = ThisDrawing.Utility.GetPoint(, "指定内部点:")
On Error Resume Next
If GetAsyncKeyState(13) = -32767 Then
'enter按下,显示面积
UserForm1.Show
Exit Do '退出循环
End If
On Err GoTo lab
ThisDrawing.SendCommand "-Boundary" & vbCr & pt(0) & "," & pt(1) & vbCr & vbCr
'如果存在边界,则会生成新的实体
If ThisDrawing.ModelSpace.Count > n Then
Set objpoly = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
'为文本框添加面积值
TextBox1.Text = objpoly.Area + Val(TextBox1.Text)
Else
MsgBox "未发现有效的边界。"
End If
Loop
Exit Sub
lab:
MsgBox Err.Description
End Sub
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'判断 enter按下
do while
'获取面积,累加
If GetAsyncKeyState(13) = -32767 Then
'enter按下,显示面积
UserForm1.Show
exit do '退出循环
End If
loop
'具体程序如下,已调试通过
'添加模块1
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'窗体代码
Private Sub CommandButton1_Click()
'当前图样的实体数目
Dim n As Long
n = ThisDrawing.ModelSpace.Count
Dim pt As Variant
Dim objpoly As AcadLWPolyline
'将控制权交给CAD
UserForm1.Hide
Do While True
'获取点的位置
pt = ThisDrawing.Utility.GetPoint(, "指定内部点:")
On Error Resume Next
If GetAsyncKeyState(13) = -32767 Then
'enter按下,显示面积
UserForm1.Show
Exit Do '退出循环
End If
On Err GoTo lab
ThisDrawing.SendCommand "-Boundary" & vbCr & pt(0) & "," & pt(1) & vbCr & vbCr
'如果存在边界,则会生成新的实体
If ThisDrawing.ModelSpace.Count > n Then
Set objpoly = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
'为文本框添加面积值
TextBox1.Text = objpoly.Area + Val(TextBox1.Text)
Else
MsgBox "未发现有效的边界。"
End If
Loop
Exit Sub
lab:
MsgBox Err.Description
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询