明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1832|回复: 2

如何判断鼠标在某个视口区域内?[已解决!]

[复制链接]
发表于 2008-7-11 01:01:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-11-14 15:59:02 编辑

如何判断鼠标在某个视口区域内?这样我就可以得到该视口的比例,相应的就可以在图纸空间中创建正确的尺寸标注了,谢谢大家!
 楼主| 发表于 2008-11-14 16:01:00 | 显示全部楼层

Public Function getVportCustomScale(ByVal Point As Variant) As Double '得到当前鼠标点击点的视口比例,如果点内没有视口返回1
Dim n As Long '视口个数
Dim minxx() As Double
Dim maxxx() As Double
Dim minyy() As Double
Dim maxyy() As Double
Dim sc() As Double '视口的比例
Dim mid As Variant
Dim h, w As Double '暂存视口的宽度和高度
Dim newVport As AcadPViewport
Dim i As Long
Dim NewEnt(0 To 0) As AcadEntity
Dim ss As AcadSelectionSet
Set ss = ThisDrawing.SelectionSets.Add("ss")
For i = 0 To ThisDrawing.PaperSpace.Count - 1
    Set NewEnt(0) = ThisDrawing.PaperSpace.Item(i)
    If NewEnt(0).ObjectName = "AcDbViewport" Then
        ss.AddItems NewEnt
    End If
Next i
n = ss.Count
ReDim minxx(0 To n) As Double
ReDim maxxx(0 To n) As Double
ReDim minyy(0 To n) As Double
ReDim maxyy(0 To n) As Double
ReDim sc(0 To n) As Double
For i = 1 To n - 1
      Set newVport = ss.Item(i)
      mid = newVport.center
      w = newVport.Width
      h = newVport.Height
      minxx(i) = mid(0) - 0.5 * w
      minyy(i) = mid(1) - 0.5 * h
      maxxx(i) = mid(0) + 0.5 * w
      maxyy(i) = mid(1) + 0.5 * h
      sc(i) = 1 / newVport.CustomScale
Next i
For i = 1 To n - 1
    If Point(0) > minxx(i) And Point(0) < maxxx(i) And Point(1) > minyy(i) And Point(1) < maxyy(i) Then
       getVportCustomScale = sc(i)'这里第i个就是鼠标所在的视口
       ss.Delete
       Exit Function
    End If
Next i
getVportCustomScale = 1

ss.Delete
End Function

发表于 2024-9-28 02:23:55 | 显示全部楼层
顶起来,正需要这个问题的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 19:25 , Processed in 0.167112 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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