nhy12345678 发表于 2008-6-5 22:21:00

[已解决]如何得到选择的多个对象的共同中心点呢?

本帖最后由 作者 于 2008-6-10 15:48:07 编辑 <br /><br /> <p>我知道一个函数,给任用一个实体绘制边框,可是如何得到实体的中心点呢? </p><p>Public&nbsp;Function&nbsp;DrawBoundingBox(ent&nbsp;As&nbsp;AcadEntity)&nbsp;As&nbsp;AcadLWPolyline<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;Min,&nbsp;Max<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ent.GetBoundingBox&nbsp;Min,&nbsp;Max<br/>&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;DrawBoundingBox&nbsp;=&nbsp;Rectangle(Min,&nbsp;Max)<br/><br/>End&nbsp;Function<br/></p>

nhy12345678 发表于 2008-6-5 22:54:00

<p>得到一个方法,但只能选择1个对象或一个块,同时选择多个对象时想得到中心点还请大家帮帮忙</p><p>Public Function GetEntMidPoint(ent As AcadEntity) As Variant '获得对象的中心点<br/>&nbsp;&nbsp;&nbsp; Dim min, max<br/>&nbsp;&nbsp;&nbsp; ent.GetBoundingBox min, max<br/>&nbsp;&nbsp;&nbsp; GetEntMidPoint = Array((min(0) + max(0)) / 2, (min(1) + max(1)) / 2, (min(2) + max(2)) / 2)<br/>End Function</p>

nhy12345678 发表于 2008-6-10 15:43:00

<p>已经解决了!思路为先得到每个对象的min max数字,在比较其他对象的min max值,遍历所有对象后得到所有对象的最大值和最小值,从而得到共同的中心点,哈哈感谢明经通道。代码如下:</p><p>Public xmin(0 To 2) As Double<br/>Public ymax(0 To 2) As Double</p><p>Public Function GetEntMaxmin(ent As AcadEntity) As Variant '获得对象的最大值最小值<br/>&nbsp;&nbsp;&nbsp; Dim min, max<br/>&nbsp;&nbsp;&nbsp; ent.GetBoundingBox min, max<br/>&nbsp;&nbsp;&nbsp; xmin(0) = min(0): xmin(1) = min(1): xmin(2) = 0<br/>&nbsp;&nbsp;&nbsp; ymax(0) = max(0): ymax(1) = max(1): ymax(2) = 0<br/>End Function</p><p>Sub dxjzY() '让选择的对象居中<br/>Dim obj() As AcadEntity<br/>Dim ent As AcadEntity<br/>Dim ss As AcadSelectionSet<br/>Dim midd(0 To 2) As Double<br/>Dim mid2(0 To 2) As Double<br/>Dim minmin(0 To 2) As Double<br/>Dim maxmax(0 To 2) As Double<br/>Dim i As Long<br/>Set ss = ThisDrawing.SelectionSets.Add("sss")<br/>ss.SelectOnScreen<br/>ReDim obj(0 To ss.Count - 1) As AcadEntity<br/>For Each ent In ss<br/>&nbsp;&nbsp;&nbsp; Set obj(i) = ent<br/>&nbsp;&nbsp;&nbsp; i = i + 1<br/>Next<br/>GetEntMaxmin obj(0)<br/>minmin(0) = xmin(0): minmin(1) = xmin(1): minmin(2) = 0<br/>maxmax(0) = ymax(0): maxmax(1) = ymax(1): maxmax(2) = 0<br/>For i = 1 To ss.Count - 1<br/>&nbsp;&nbsp; Set obj(i) = ss.Item(i)<br/>&nbsp;&nbsp; GetEntMaxmin obj(i)<br/>&nbsp;&nbsp; If minmin(0) &gt; xmin(0) Then minmin(0) = xmin(0)<br/>&nbsp;&nbsp; If minmin(1) &gt; xmin(1) Then minmin(1) = xmin(1)<br/>&nbsp;&nbsp; If maxmax(0) &lt; ymax(0) Then maxmax(0) = ymax(0)<br/>&nbsp;&nbsp; If maxmax(1) &lt; ymax(1) Then maxmax(1) = ymax(1)<br/>Next i<br/>'midd为选择一系列对象的中心点<br/>midd(0) = (minmin(0) + maxmax(0)) * 0.5<br/>midd(1) = (minmin(1) + maxmax(1)) * 0.5<br/>midd(2) = 0<br/>ss.Delete<br/>End Sub</p>

robbin840311 发表于 2008-6-10 16:16:00

<p>请LZ关注下</p><p><a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=68254">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=68254</a></p><p></p>
页: [1]
查看完整版本: [已解决]如何得到选择的多个对象的共同中心点呢?