Layer Color to Layer Material Color

This rhino script allows the user to match the layers material color to that layer’s layer color.  If no layer material has been applied the script will create a new layer material and match its color.

Rhino Script

Option Explicit 
'Script written by <David Mans> 
'Script copyrighted by <NeoArchaic Design> 
'Script version Wednesday, 16 February 2011 12:03:34 
Call Main() 
Sub Main() 
	Dim strLayer 
	strLayer = Rhino.GetLayer("Select Layers To Match") 
	If isNull(strLayer) Then Exit Sub       
	Call Rhino.EnableRedraw(False) 
	Dim intMat, ingColor 
	intMat = Rhino.LayerMaterialIndex(strLayer) 
	ingColor = Rhino.LayerColor(strLayer) 
	If intMat < 0 Then 
		intMat = Rhino.AddMaterialToLayer(strLayer) 
	End If 
	Call Rhino.MaterialColor(intMat, ingColor) 
	Call Rhino.EnableRedraw(True) 
End Sub