Bill Tillman Posted September 4, 2012 Posted September 4, 2012 I'm using the following function I found somewhere to add new layers and set colors for them using VBA. The trouble is the layers I want to set to white, which would normally print just black lines on paper. Function CreateLayer(ByVal namelayer As String, ByVal R, G, B As Double) On Error Resume Next Dim color As AcadAcCmColor Dim newlayer As AcadLayer 'Select Layer or if not exists create a new layer Set newlayer = ThisDrawing.Layers.Add(namelayer) If Err > 0 Then Set newlayer = ThisDrawing.Layers.Item(namelayer) Err.Clear End If 'Set AutoCAD Color Objects If Left(AutoCAD.Application.ActiveDocument.GetVariable("acadver"), 2) = "16" Then Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16") ElseIf Left(AutoCAD.Application.ActiveDocument.GetVariable("acadver"), 2) = "17" Then Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17") ElseIf Left(AutoCAD.Application.ActiveDocument.GetVariable("acadver"), 2) = "19" Then Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.19") Else MsgBox "Wrong Autocad version for this function" Exit Function End If 'R,B,G stands for Red, Green, Blue value Call color.SetRGB(R, G, B) 'Create a Layer and make it the active layer newlayer.TrueColor = color 'ThisDrawing.ActiveLayer = newlayer End Function With the RGB method used herein I pass the values of 255, 255, 255 and it sets the layer color accordingly. However, that is apparently not the same as setting the layer to White and the results are the lines set to 255, 255, 255 are not printing in either the preview or on the printer. I've tried some other choices, including 0,0,0 which shows up on the printer but in the model space the black lines are just too hard to see. What's the secret for using White as the color to pass to RGB values? Quote
BlackBox Posted September 4, 2012 Posted September 4, 2012 FWIW - It looks like Oleg specifies 256 using ColorMethod = acColorMethodByRGB Option Explicit Sub ChangeLayerColor() Dim oLay As AcadLayer Dim lngCol As Long Dim aCol As AcadAcCmColor On Error GoTo Err_Control Set aCol = New AcadAcCmColor aCol.ColorMethod = acColorMethodByRGB lngCol = CLng(InputBox(vbCr & "Specify color index number for layer: ", "Layer Color", "121")) If lngCol < 0 Or lngCol > 256 Then MsgBox "Use a color index number from 0 to 256" Exit Sub End If aCol.ColorIndex = lngCol Set oLay = ThisDrawing.Layers("0") oLay.TrueColor = aCol Set aCol = Nothing Err_Control: If Err Then MsgBox Err.Description End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.