Bill Tillman 发表于 2022-7-6 22:27:31

使用设置图层颜色

我正在使用我在某处找到的以下函数来添加新层,并使用VBA为其设置颜色。问题是我想将图层设置为白色,通常只在纸上打印黑色线条。
 

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

 
使用本文使用的RGB方法,我传递255、255、255的值,并相应地设置层颜色。但是,这显然不同于将图层设置为白色,结果是设置为255的行、255、255没有在预览或打印机上打印。我尝试了其他一些选择,包括0,0,0,它显示在打印机上,但在模型空间中,黑线太难看到。使用白色作为颜色传递到RGB值的秘密是什么?

BlackBox 发表于 2022-7-6 23:54:32

FWIW-看起来Oleg使用ColorMethod=acColorMethodByRGB指定了256
 
页: [1]
查看完整版本: 使用设置图层颜色