RemoveItems方法为什么不对(請飛狐版主幫忙)
本帖最后由 作者 于 2006-8-22 12:18:49 编辑 <br /><br /> <P>本人是想做个颜色过滤的程式:先选一个参考物体,看其颜色是什么(假如acred),然后框选屏幕,理想是只能选择与参考物体颜色一样(acred)的物体,包括层物体颜色为bylayer,而对应层也是acred的</P><P>为了能选取颜色可能为bylayer而其实对应层的颜色也为acred的物体,我第二次框选了所有颜色为bylarer的物体,然后将那些颜色为bylayer而其对应的层的颜色不为acred物体过滤掉,如下用红色程式处(RemoveItems方法),为什么没有过滤掉呢,请大师指点 (我觉得错误可能在绿色程式处,因为刚开始redim Robj(0)的时候没有东西,即Robj(1)才开始有东西,可是好象必须redim Robj(0),要不提示了下标超界)</P>
<P> Public Sub Ys()<BR>On Error Resume Next<BR>Dim Ssetobj As AcadSelectionSet, Str As Integer, Obj As AcadEntity, Pt As Variant<BR>Dim La As String, Robj() As AcadObject, I As Integer, Lb As String, Co As Integer, Ro As AcadObject<BR>ThisDrawing.Utility.GetEntity Obj, Pt: Obj.Highlight True<BR>Str = Obj.color<BR>If Str = 256 Then<BR> La = Obj.Layer<BR> Str = ThisDrawing.Layers(La).color<BR>End If<BR>ThisDrawing.SelectionSets("ys").Delete<BR>Err.Clear<BR>Set Ssetobj = ThisDrawing.SelectionSets.Add("ys")<BR>Dim Ftype(3) As Integer, Fdata(3) As Variant<BR><FONT color=#09f738>ReDim Robj(0) As AcadObject</FONT><BR>Ftype(0) = -4: Fdata(0) = "<OR"<BR>Ftype(1) = 62: Fdata(1) = Str<BR>Ftype(2) = 62: Fdata(2) = acByLayer<BR>Ftype(3) = -4: Fdata(3) = "OR>"<BR>Ssetobj.SelectOnScreen Ftype, Fdata<BR>For I = 0 To Ssetobj.Count - 1<BR> Set Ro = Ssetobj.Item(I)<BR> Lb = Ro.Layer<BR> Co = ThisDrawing.Layers(Lb).color<BR> Select Case Co<BR> Case Is <> Str<BR><FONT color=#69ee11> <FONT color=#33ff00>ReDim Preserve Robj(UBound(Robj) + 1)</FONT><BR></FONT> Set Robj(UBound(Robj)) = Ro<BR> End Select<BR>Next I<BR>Robj(0).Delete<BR><FONT color=#f73809>Ssetobj.RemoveItems (Robj)<BR></FONT>End Sub</P> <P>For I = 0 To Ssetobj.Count - 1<BR> Set Ro = Ssetobj.Item(I)<BR> Lb = Ro.Layer<BR> Co = ThisDrawing.Layers(Lb).color<BR> Select Case Co<BR> Case Is <> Str<BR><FONT color=#69ee11> <FONT color=#33ff00>ReDim Preserve Robj(UBound(Robj) + 1)</FONT><BR></FONT> Set Robj(UBound(Robj)) = Ro<BR> End Select<BR>Next I<BR>Robj(0).Delete<BR><FONT color=#f73809>Ssetobj.RemoveItems (Robj)<BR>'这段有何用?</FONT></P>
<P><FONT color=#f73809>前面的已经能实现你的要求了啊</FONT></P> 前面程式有缺陷,你要是画一些顏色为bylayer的它都可以选的(虽然和参考物体的顏色不一样)
页:
[1]