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