[已解决]如何得到选择的多个对象的共同中心点呢?
本帖最后由 作者 于 2008-6-10 15:48:07 编辑 <br /><br /> <p>我知道一个函数,给任用一个实体绘制边框,可是如何得到实体的中心点呢? </p><p>Public Function DrawBoundingBox(ent As AcadEntity) As AcadLWPolyline<br/><br/> Dim Min, Max<br/> <br/> ent.GetBoundingBox Min, Max<br/> Set DrawBoundingBox = Rectangle(Min, Max)<br/><br/>End Function<br/></p> <p>得到一个方法,但只能选择1个对象或一个块,同时选择多个对象时想得到中心点还请大家帮帮忙</p><p>Public Function GetEntMidPoint(ent As AcadEntity) As Variant '获得对象的中心点<br/> Dim min, max<br/> ent.GetBoundingBox min, max<br/> GetEntMidPoint = Array((min(0) + max(0)) / 2, (min(1) + max(1)) / 2, (min(2) + max(2)) / 2)<br/>End Function</p> <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/> Dim min, max<br/> ent.GetBoundingBox min, max<br/> xmin(0) = min(0): xmin(1) = min(1): xmin(2) = 0<br/> 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/> Set obj(i) = ent<br/> 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/> Set obj(i) = ss.Item(i)<br/> GetEntMaxmin obj(i)<br/> If minmin(0) > xmin(0) Then minmin(0) = xmin(0)<br/> If minmin(1) > xmin(1) Then minmin(1) = xmin(1)<br/> If maxmax(0) < ymax(0) Then maxmax(0) = ymax(0)<br/> If maxmax(1) < 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> <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]