This sub does something similar. You can modify it to suit you.
Public Sub ColorToByLayer()
'This subroutine sets each entity's color from
'a specific color to ByLayer and moves it to
'a layer with the name of the former color.
Dim objEntity As AcadEntity
Dim objMS As AcadModelSpace
Dim objPS As AcadBlock
Dim objLayers As AcadLayers
Dim objLayer As AcadLayer
Dim objLayout As AcadLayout
Dim cnt As Integer
Dim strLayer As String
Set objLayers = ThisDrawing.Layers
cnt = 0
For Each objLayout In ThisDrawing.Layouts
'process ents in modelspace
If objLayout.ModelType = True Then
Set objMS = ThisDrawing.ModelSpace
For Each objEntity In objMS
If Not objEntity.color = acByLayer Then
strLayer = "CBL_" & objEntity.color
Set objLayer = objLayers.Add(strLayer)
objLayer.color = objEntity.color
objEntity.Layer = strLayer
objEntity.color = acByLayer
cnt = cnt + 1
Else
End If
Next objEntity
Else
'process ents in paperspace
Set objPS = objLayout.Block
For Each objEntity In objPS
If Not objEntity.color = acByLayer Then
strLayer = "CBL_" & objEntity.color
Set objLayer = objLayers.Add(strLayer)
objLayer.color = objEntity.color
objEntity.Layer = strLayer
objEntity.color = acByLayer
cnt = cnt + 1
Else
End If
Next objEntity
End If
Next objLayout
If cnt > 0 Then
MsgBox cnt & " items were changed to color ByLayer.", vbInformation, "Change Color to ByLayer"
Else
'Everything is ok, minimize user interaction.
ThisDrawing.Utility.Prompt "Color ByLayer check: OK" & vbCrLf & "Command: "
End If
End Sub
Ed
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to
post your code.