[求助]如何得到图纸空间视口四点的坐标
<p>现在图纸空间有一个矩形视口,如何得到这四个角点在模型空间的坐标。</p><p>即如何根据模型空间的一个矩形,新建一个视口正好与这个矩形相重合。</p><p>看了下帮助,好像没有讲视口显示的模型空间的基点啊!</p> <p>Public Sub VPCoords(vp As AcadPViewport, ll, ur)</p><p> Dim min, max, oldMode As Boolean<br/> <br/> vp.GetBoundingBox min, max<br/> oldMode = ThisDrawing.MSpace<br/> ThisDrawing.MSpace = True<br/> ll = ThisDrawing.Utility.TranslateCoordinates(min, acPaperSpaceDCS, acDisplayDCS, False)<br/> ur = ThisDrawing.Utility.TranslateCoordinates(max, acPaperSpaceDCS, acDisplayDCS, False)<br/> ThisDrawing.MSpace = oldMode<br/> <br/>End Sub<br/>这个可以实现,不过要倒过来如何实现呢。就是知一个矩形及比例,如何生成一个大小相同的视口?</p> <p>对啊,为什么没人回答。我也遇到这个问题。急啊。</p> 我的问题解决了,在视口中,用zoomwindows,可以实现。 <p>楼主:</p><p> 请明示吧。怎么用zoomwindows命令。我在开发文档里没有发现这个命令啊。用Vpcoords为什么我转成acWorld坐标里就不行了呢。没有输出。多谢。</p> <p>Sub sk_jl() '根据两点及比较在图纸空间新建视口<br/> Dim returnObj As AcadObject<br/> Dim vv As AcadPViewport<br/> <br/> Dim basePnt1 As Variant<br/> Dim basePnt2 As Variant<br/> Dim leftlow(0 To 2) As Double<br/> Dim righttow(0 To 2) As Double<br/> Dim bl As Double<br/> Dim kd As Double<br/> Dim gd As Double<br/> Dim jd As Double<br/> <br/> UserForm3.Show<br/> gd = 250<br/> bl = UserForm3.TextBox1.Value '比例<br/> <br/> Dim returnPnt As Variant<br/> 'On Error Resume Next<br/> ThisDrawing.ActiveSpace = acModelSpace<br/> <br/> basePnt1 = ThisDrawing.Utility.GetPoint(, "Enter a point: ")<br/> basePnt2 = ThisDrawing.Utility.GetPoint(, "Enter a Next point: ")<br/> <br/> jd = fwj(basePnt2(0) - basePnt1(0), basePnt2(1) - basePnt1(1)) '计算角度<br/> kd = ((basePnt2(0) - basePnt1(0)) ^ 2 + (basePnt2(1) - basePnt1(1)) ^ 2) ^ 0.5 * bl</p><p> leftlow(0) = basePnt1(0) + gd / 2 * bl * Cos(jd - 3.1415926 / 2)<br/> leftlow(1) = basePnt1(1) + gd / 2 * bl * Sin(jd - 3.1415926 / 2)<br/> righttow(0) = basePnt2(0) + gd / 2 * bl * Cos(jd + 3.1415926 / 2)<br/> righttow(1) = basePnt2(1) + gd / 2 * bl * Sin(jd + 3.1415926 / 2)<br/> ' ThisDrawing.ModelSpace.AddLine leftlow, righttow<br/> <br/> Dim pviewportObj As AcadPViewport<br/> Dim center(0 To 2) As Double<br/> center(0) = 200: center(1) = 200: center(2) = 0<br/> <br/> ThisDrawing.ActiveSpace = acPaperSpace<br/> Set pviewportObj = ThisDrawing.PaperSpace.AddPViewport(center, kd, gd)<br/> pviewportObj.Display True<br/> <br/> pviewportObj.twistAngle = 2 * 3.1415926 - jd '旋转角度<br/> <br/> ThisDrawing.MSpace = True<br/> ThisDrawing.Application.ZoomWindow leftlow, righttow<br/> ThisDrawing.MSpace = False</p><p> ThisDrawing.Regen acAllViewports<br/> <br/> <br/>End Sub</p><p></p><p>学了半天时间才搞的程序。</p> 这是一个好办法。楼主。就是知道了模型空间的矩形位置较容易在图纸空间建立新的视口。但反过来,如何将已建立了的视口对应的模型空间的范围的角点找到呢。我发现vpcoords我用不好。转出来的坐标是什么坐标。怎么不是布局里对应的点呢。差太多了。 <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 & " " & vp.Height<br/>End Sub<br/></p> <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) & " " & minP(1) & vbNewLine & maxP(0) & " " & maxP(1)</p><p>End Sub</p> <p>楼主:</p><p> 我的视口是不规则图形,是多边形吧。我用vpcoords可以将其psdcs转到DCS ,然后再将DCS转到WCS。我会用了。但事先要采用GetBoundingBox获得视口的各点,这点我在想。并且即使采用了GetBoundingBox,其返回的数据也并不是我的视口的最外边。不知道为什么。</p>
页:
[1]
2