fjfhgdwfn 发表于 2009-2-10 11:30:00

[求助]如何得到图纸空间视口四点的坐标

<p>现在图纸空间有一个矩形视口,如何得到这四个角点在模型空间的坐标。</p><p>即如何根据模型空间的一个矩形,新建一个视口正好与这个矩形相重合。</p><p>看了下帮助,好像没有讲视口显示的模型空间的基点啊!</p>

fjfhgdwfn 发表于 2009-2-10 13:47:00

<p>Public Sub VPCoords(vp As AcadPViewport, ll, ur)</p><p>&nbsp;&nbsp;&nbsp; Dim min, max, oldMode As Boolean<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; vp.GetBoundingBox min, max<br/>&nbsp;&nbsp;&nbsp; oldMode = ThisDrawing.MSpace<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.MSpace = True<br/>&nbsp;&nbsp;&nbsp; ll = ThisDrawing.Utility.TranslateCoordinates(min, acPaperSpaceDCS, acDisplayDCS, False)<br/>&nbsp;&nbsp;&nbsp; ur = ThisDrawing.Utility.TranslateCoordinates(max, acPaperSpaceDCS, acDisplayDCS, False)<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.MSpace = oldMode<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub<br/>这个可以实现,不过要倒过来如何实现呢。就是知一个矩形及比例,如何生成一个大小相同的视口?</p>

jiapeng2008 发表于 2009-2-27 18:55:00

<p>对啊,为什么没人回答。我也遇到这个问题。急啊。</p>

fjfhgdwfn 发表于 2009-2-27 20:02:00

我的问题解决了,在视口中,用zoomwindows,可以实现。

jiapeng2008 发表于 2009-2-27 21:35:00

<p>楼主:</p><p>&nbsp;&nbsp;&nbsp; 请明示吧。怎么用zoomwindows命令。我在开发文档里没有发现这个命令啊。用Vpcoords为什么我转成acWorld坐标里就不行了呢。没有输出。多谢。</p>

fjfhgdwfn 发表于 2009-2-27 22:18:00

<p>Sub sk_jl() '根据两点及比较在图纸空间新建视口<br/>&nbsp;&nbsp;&nbsp; Dim returnObj As AcadObject<br/>&nbsp;&nbsp;&nbsp; Dim vv As AcadPViewport<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim basePnt1 As Variant<br/>&nbsp;&nbsp;&nbsp; Dim basePnt2 As Variant<br/>&nbsp;&nbsp;&nbsp; Dim leftlow(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim righttow(0 To 2)&nbsp; As Double<br/>&nbsp;&nbsp;&nbsp; Dim bl As Double<br/>&nbsp;&nbsp;&nbsp; Dim kd As Double<br/>&nbsp;&nbsp;&nbsp; Dim gd As Double<br/>&nbsp;&nbsp;&nbsp; Dim jd As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; UserForm3.Show<br/>&nbsp;&nbsp;&nbsp; gd = 250<br/>&nbsp;&nbsp;&nbsp; bl = UserForm3.TextBox1.Value&nbsp;'比例<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp; Dim returnPnt As Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp; 'On Error Resume Next<br/>&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveSpace = acModelSpace<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; basePnt1 = ThisDrawing.Utility.GetPoint(, "Enter a point: ")<br/>&nbsp;&nbsp;&nbsp; basePnt2 = ThisDrawing.Utility.GetPoint(, "Enter a&nbsp; Next point: ")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; jd = fwj(basePnt2(0) - basePnt1(0), basePnt2(1) - basePnt1(1)) '计算角度<br/>&nbsp;&nbsp;&nbsp; kd = ((basePnt2(0) - basePnt1(0)) ^ 2 + (basePnt2(1) - basePnt1(1)) ^ 2) ^ 0.5 * bl</p><p>&nbsp;&nbsp;&nbsp; leftlow(0) = basePnt1(0) + gd / 2 * bl * Cos(jd - 3.1415926 / 2)<br/>&nbsp;&nbsp;&nbsp; leftlow(1) = basePnt1(1) + gd / 2 * bl * Sin(jd - 3.1415926 / 2)<br/>&nbsp;&nbsp;&nbsp; righttow(0) = basePnt2(0) + gd / 2 * bl * Cos(jd + 3.1415926 / 2)<br/>&nbsp;&nbsp;&nbsp; righttow(1) = basePnt2(1) + gd / 2 * bl * Sin(jd + 3.1415926 / 2)<br/>&nbsp;&nbsp; ' ThisDrawing.ModelSpace.AddLine leftlow, righttow<br/>&nbsp; <br/>&nbsp;&nbsp; Dim pviewportObj As AcadPViewport<br/>&nbsp;&nbsp;&nbsp; Dim center(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;center(0) = 200: center(1) = 200: center(2) = 0<br/>&nbsp;<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveSpace = acPaperSpace<br/>&nbsp;&nbsp;&nbsp; Set pviewportObj = ThisDrawing.PaperSpace.AddPViewport(center, kd, gd)<br/>&nbsp;&nbsp;&nbsp;&nbsp; pviewportObj.Display True<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; pviewportObj.twistAngle = 2 * 3.1415926 - jd '旋转角度<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ThisDrawing.MSpace = True<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Application.ZoomWindow leftlow, righttow<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.MSpace = False</p><p>&nbsp;&nbsp; ThisDrawing.Regen acAllViewports<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>End Sub</p><p></p><p>学了半天时间才搞的程序。</p>

jiapeng2008 发表于 2009-2-27 22:37:00

这是一个好办法。楼主。就是知道了模型空间的矩形位置较容易在图纸空间建立新的视口。但反过来,如何将已建立了的视口对应的模型空间的范围的角点找到呢。我发现vpcoords我用不好。转出来的坐标是什么坐标。怎么不是布局里对应的点呢。差太多了。

wuyunpeng888 发表于 2009-2-27 23:27:00

<p>你要的是这个吗?</p><p>Public Sub tests()<br/>Dim vp As AcadEntity<br/>Set vp = ThisDrawing.Blocks.Item("*Paper_Space").Item(0)<br/>MsgBox vp.Width &amp; "&nbsp;&nbsp;&nbsp; " &amp; vp.Height<br/>End Sub<br/></p>

wuyunpeng888 发表于 2009-2-27 23:31:00

<p>还是这个?</p><p>Public Sub tests()<br/>Dim vp As AcadEntity, minP As Variant, maxP As Variant<br/>Set vp = ThisDrawing.Blocks.Item("*Paper_Space").Item(0)<br/>vp.GetBoundingBox minP, maxP<br/>MsgBox minP(0) &amp; "&nbsp; " &amp; minP(1) &amp; vbNewLine &amp; maxP(0) &amp; "&nbsp; " &amp; maxP(1)</p><p>End Sub</p>

jiapeng2008 发表于 2009-2-27 23:48:00

<p>楼主:</p><p>&nbsp;&nbsp;&nbsp; 我的视口是不规则图形,是多边形吧。我用vpcoords可以将其psdcs转到DCS ,然后再将DCS转到WCS。我会用了。但事先要采用GetBoundingBox获得视口的各点,这点我在想。并且即使采用了GetBoundingBox,其返回的数据也并不是我的视口的最外边。不知道为什么。</p>
页: [1] 2
查看完整版本: [求助]如何得到图纸空间视口四点的坐标