[VBA]怎么修改颜色??
如果实体的颜色是随层显示,怎么样运用选择集有选择地修改其颜色?[VBA]
本帖最后由 作者 于 2005-1-31 13:32:14 编辑比如一个DWG文件,里面的实体的颜色,图层都很乱,需要按实体颜色的不同进行归入不同的图层,但有些实体的颜色为随层显示,我编的程序对随层显示的实体不起作用,请大家指点;我的程序 Sub qingli()<BR>Dim tuceng As AcadLayer<BR>On Error Resume Next<BR>If IsNull(ThisDrawing.Layers.Item("0")) Then<BR> Set tuceng = ThisDrawing.Layers.Add("0")<BR> tuceng.color = 7<BR> tuceng.Lineweight = acLnWt035<BR>End If
If IsNull(ThisDrawing.Layers.Item("细线")) Then<BR> Set tuceng = ThisDrawing.Layers.Add("细线")<BR> tuceng.color = 1<BR> tuceng.Lineweight = acLnWt013<BR>End If<BR>Dim SSset As AcadSelectionSet '建立选择集"SS1"<BR>Dim enti As AcadEntity<BR>If Not IsNull(ThisDrawing.SelectionSets.Item("SS1")) Then<BR> Set SSset = ThisDrawing.SelectionSets.Item("SS1")<BR> SSset.Delete<BR>End If<BR>Set SSset = ThisDrawing.SelectionSets.Add("SS1")<BR>Dim filterType As Integer<BR>Dim filterData As Variant<BR>filterType = 8<BR>For Each tuceng In ThisDrawing.Layers<BR>filterType = tuceng.Name<BR>SSset.Select acSelectionSetAll<BR>For Each enti In SSset
If enti.Layer = "0" Then '图层"0"<BR> If tuceng.color = 7 Then<BR> If enti.color = acByLayer Or enti.color = 7 Or enti.color = acByBlock Then<BR> ' MsgBox tuceng.Name & "," & enti.color<BR> enti.color = 7<BR> enti.Update<BR> Else<BR> 'MsgBox tuceng.Name & "," & enti.color<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> ElseIf tuceng.color = 1 Then<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> Else<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> End If<BR> 'End If<BR> ElseIf enti.Layer = "细线" Then '图层"细线"<BR> If tuceng.color = 7 Then<BR> If enti.color = acByLayer Or enti.color = 7 Or enti.color = acByBlock Then<BR> MsgBox tuceng.Name & tuceng.color & enti.color<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> 'MsgBox tuceng.Name & "," & enti.color<BR> enti.color = 1<BR> 'enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> ElseIf tuceng.color = 1 Then<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> 'enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> Else<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> 'enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> End If<BR> 'End If<BR> Else ' enti.Layer <> "细线" And enti.Layer <> "0" Then '图层"其它"<BR> If tuceng.color = 7 Then<BR> If enti.color = acByLayer Or enti.color = 7 Or enti.color = acByBlock Then<BR> MsgBox tuceng.Name '& "," & enti.color<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> 'MsgBox tuceng.Name & "," & enti.color<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> ElseIf tuceng.color = 1 Then<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> Else<BR> If enti.color = 7 Or enti.color = acByBlock Then<BR> enti.color = 7<BR> enti.Layer = "0"<BR> enti.Update<BR> Else<BR> enti.color = 1<BR> enti.Layer = "细线"<BR> enti.Update<BR> End If<BR> End If<BR> End If
Next enti<BR>Next tuceng<BR>For Each tuceng In ThisDrawing.Layers<BR> If tuceng.Name = "0" Then<BR> tuceng.color = 7<BR> tuceng.Lineweight = acLnWt035<BR> End If<BR> If tuceng.Name = "细线" Then<BR> tuceng.color = 1<BR> tuceng.Lineweight = acLnWt013<BR> End If<BR> If tuceng.Name <> "0" And tuceng.Name <> "细线" And tuceng.Name <> "定义点" And tuceng.Name <> "Defpoints" Then<BR> tuceng.Delete<BR> End If<BR>Next tuceng<BR>SSset.clease<BR>SSset.Delete
End Sub<BR> 选择图层为0,且随层,或者颜色为红色的实体:
Sub tta()<BR>On Error Resume Next<BR>Dim ss As AcadSelectionSet<BR>ThisDrawing.SelectionSets("Test").Delete<BR>Set ss = ThisDrawing.SelectionSets.Add("Test")<BR>Dim ft(6) As Integer, fd(6)<BR>ft(0) = -4: fd(0) = "<or"<BR>ft(1) = -4: fd(1) = "<and"<BR>ft(2) = 8: fd(2) = "0"<BR>ft(3) = 62: fd(3) = 256<BR>ft(4) = -4: fd(4) = "and>"<BR>ft(5) = 62: fd(5) = 1<BR>ft(6) = -4: fd(6) = "or>"<BR>ss.Select acSelectionSetAll, , , ft, fd<BR>MsgBox ss.Count<BR> 我对DXF不是很懂,也找不到这方面的资料!能否给我传一点过来,我的QQ79570611
邮箱:bai_cai101@163.com,多谢你了!!!!
<or,<and等我都不知道怎么用它??? DXF 参考手册帮助里就有 谢谢你, 我看了一下DXF帮助,但没有看到像<or,<and 之类的说明!!版主能否再给几个例子让我模仿一下!多谢你了!!比如我想将实体按颜色归入不同的图层!白色的实体(包括随层,随块颜色)放入图层"0",红色放入"细线"图层,
页:
[1]