nhy12345678 发表于 2008-7-11 01:01:00

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

本帖最后由 作者 于 2008-11-14 15:59:02 编辑

如何判断鼠标在某个视口区域内?这样我就可以得到该视口的比例,相应的就可以在图纸空间中创建正确的尺寸标注了,谢谢大家!

nhy12345678 发表于 2008-11-14 16:01:00

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

尘缘一生 发表于 2024-9-28 02:23:55

顶起来,正需要这个问题的
页: [1]
查看完整版本: 如何判断鼠标在某个视口区域内?[已解决!]