效果如下:
一、所有图元颜色为bylayer
Sub 图元颜色跟随图层()
Dim item As AcadEntityFor Each item In ThisDrawing.ModelSpace
item.color = acByLayer
Next
ThisDrawing.Regen acActiveViewport
End Sub
二、与图层颜色相同(不是bylayer):
Sub 图元颜色跟随图层()
Dim item As AcadEntity
Dim itemlayer As AcadLayerFor Each item In ThisDrawing.ModelSpacelayername = item.LayerSet itemlayer = ThisDrawing.Layers(layername)item.color = itemlayer.color NextThisDrawing.Regen acActiveViewport
End Sub