luckyliya 发表于 2006-4-5 10:37:00

(求助)为什么不支持质心属性

<P>我编了一段程序,想求面积最大的面域的质心,代码如下:</P>
<P>Public Sub zx()<BR>&nbsp;&nbsp;&nbsp; Dim pt As Variant<BR>&nbsp;&nbsp;&nbsp; Dim spt1 As String<BR>&nbsp;&nbsp;&nbsp; Dim spt2 As String<BR>&nbsp;&nbsp;&nbsp; spt1 = 0 &amp; "," &amp; 0<BR>&nbsp;&nbsp;&nbsp; spt2 = 400 &amp; "," &amp; 400<BR>&nbsp;&nbsp;&nbsp; Dim n As Variant<BR>&nbsp;&nbsp;&nbsp; '创建面域<BR>&nbsp;&nbsp;&nbsp; Dim ssetobj As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>'清空选择集中已有的选择集,避免重名<BR>&nbsp; If ThisDrawing.SelectionSets.count &gt; 0 Then<BR>&nbsp;&nbsp;&nbsp; For i = 0 To ThisDrawing.SelectionSets.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Clear<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Delete<BR>&nbsp;&nbsp; Next<BR>&nbsp;End If<BR>&nbsp;&nbsp; ThisDrawing.SendCommand "region" &amp; vbCr &amp; spt1 &amp; vbCr &amp; spt2 &amp; vbCr &amp; vbCr<BR>&nbsp;&nbsp;&nbsp; Set ssetobj = ThisDrawing.SelectionSets.Add("ss")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim FType(0) As Integer<BR>&nbsp;&nbsp;&nbsp; Dim FData(0) As Variant<BR>&nbsp;&nbsp;&nbsp; FType(0) = 0<BR>&nbsp;&nbsp;&nbsp; FData(0) = "region"<BR>&nbsp;&nbsp;&nbsp; Dim FilterType As Variant<BR>&nbsp;&nbsp;&nbsp; Dim FilterData As Variant<BR>&nbsp;&nbsp;&nbsp; FilterType = FType<BR>&nbsp;&nbsp;&nbsp; FilterData = FData<BR>&nbsp;&nbsp;&nbsp; ssetobj.Select acSelectionSetAll, , , FilterType, FilterData<BR>&nbsp;&nbsp;&nbsp; k = ssetobj.count<BR>&nbsp;&nbsp;&nbsp; MsgBox k</P>
<P>&nbsp;&nbsp;&nbsp; Dim area As Double<BR>&nbsp;&nbsp;&nbsp; Dim maxarea As Double<BR>&nbsp;&nbsp;&nbsp; maxarea = 1<BR>&nbsp;&nbsp;&nbsp; Dim pregion As AcadRegion<BR>&nbsp;&nbsp;&nbsp; Dim centriod As Variant<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 0 To ssetobj.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; area = ssetobj.Item(i).area<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If maxarea &lt; area Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxarea = area<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 0 To ssetobj.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ssetobj.Item(i).area = maxarea Then<BR>&nbsp;&nbsp;&nbsp;<FONT color=#a0a0a0>&nbsp;&nbsp; </FONT><FONT color=#ee3d11>centriod = ssetobj.Item(i).centriod</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; MsgBox maxarea<BR>&nbsp;&nbsp; MsgBox centriod<BR>&nbsp; ssetobj.Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp; End Sub</P>
<P>加红的一段代码中,把centriod 改成area或perimeter都可以,但改成centriod时,系统提示</P>
<P>"对象不支持该属性或方法"</P>
<P>为什么系统支持面积和周长属性,而不支持质心属性呢?</P>
<P>我是初学者,请各位高手帮帮忙?提提意见也好!</P>

luckyliya 发表于 2006-4-5 14:16:00

<P>不好意思,其是的centriod 应改成centroid</P>

luckyliya 发表于 2006-4-5 14:21:00

<P>调出来了,以下是可运行的代码:</P>
<P>&nbsp;</P>
<P>Public Sub zx()<BR>&nbsp;&nbsp;&nbsp; Dim pt As Variant<BR>&nbsp;&nbsp;&nbsp; Dim spt1 As String<BR>&nbsp;&nbsp;&nbsp; Dim spt2 As String<BR>&nbsp;&nbsp;&nbsp; spt1 = 0 &amp; "," &amp; 0<BR>&nbsp;&nbsp;&nbsp; spt2 = 400 &amp; "," &amp; 400<BR>&nbsp;&nbsp;&nbsp; Dim n As Variant<BR>&nbsp;&nbsp;&nbsp; '创建面域<BR>&nbsp;&nbsp;&nbsp; Dim ssetobj As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>'清空选择集中已有的选择集,避免重名<BR>&nbsp; If ThisDrawing.SelectionSets.count &gt; 0 Then<BR>&nbsp;&nbsp;&nbsp; For i = 0 To ThisDrawing.SelectionSets.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Clear<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Delete<BR>&nbsp;&nbsp; Next<BR>&nbsp;End If<BR>&nbsp;&nbsp; ThisDrawing.SendCommand "region" &amp; vbCr &amp; spt1 &amp; vbCr &amp; spt2 &amp; vbCr &amp; vbCr<BR>&nbsp;&nbsp;&nbsp; Set ssetobj = ThisDrawing.SelectionSets.Add("ss")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim FType(0) As Integer<BR>&nbsp;&nbsp;&nbsp; Dim FData(0) As Variant<BR>&nbsp;&nbsp;&nbsp; FType(0) = 0<BR>&nbsp;&nbsp;&nbsp; FData(0) = "region"<BR>&nbsp;&nbsp;&nbsp; Dim FilterType As Variant<BR>&nbsp;&nbsp;&nbsp; Dim FilterData As Variant<BR>&nbsp;&nbsp;&nbsp; FilterType = FType<BR>&nbsp;&nbsp;&nbsp; FilterData = FData<BR>&nbsp;&nbsp;&nbsp; ssetobj.Select acSelectionSetAll, , , FilterType, FilterData<BR>&nbsp;&nbsp;&nbsp; k = ssetobj.count<BR>&nbsp;&nbsp;&nbsp; MsgBox k</P>
<P>&nbsp;&nbsp;&nbsp; Dim area As Double<BR>&nbsp;&nbsp;&nbsp; Dim maxarea As Double<BR>&nbsp;&nbsp;&nbsp; maxarea = 1<BR>&nbsp;&nbsp;&nbsp; Dim pregion As AcadRegion<BR>&nbsp;&nbsp;&nbsp; Dim centroid As Variant<BR>&nbsp;&nbsp;&nbsp; Dim x As Double<BR>&nbsp;&nbsp;&nbsp; Dim y As Double<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 0 To ssetobj.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; area = ssetobj.Item(i).area<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If maxarea &lt; area Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxarea = area<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; For i = 0 To ssetobj.count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ssetobj.Item(i).area = maxarea Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centroid = ssetobj.Item(i).centroid<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = centroid(0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = centroid(1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; MsgBox maxarea<BR>&nbsp;&nbsp; MsgBox (x &amp; "," &amp; y)<BR>&nbsp; ssetobj.Delete<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp; End Sub</P>
页: [1]
查看完整版本: (求助)为什么不支持质心属性