Set ColorIndex instead of RGB
Moderators: SDS, support, admin
Set ColorIndex instead of RGB
Hello~
I want to set the layer color as ColorIndex instead of RGB.
when I print out a drawing, polylines with white(ColorIndex: 7) come out as black.
However, RGB white color doesn't come out as black.
My code is below.
CADLayer layer = new CADLayer()
{
Name = "layer_name",
Color = System.Drawing.Color.White // or Color.FromArgb(255)
};
Is there any way to set ColorIndex to layer or polyline?
If not, do you have any idea to convert the white color to black when printing out?
I want to set the layer color as ColorIndex instead of RGB.
when I print out a drawing, polylines with white(ColorIndex: 7) come out as black.
However, RGB white color doesn't come out as black.
My code is below.
CADLayer layer = new CADLayer()
{
Name = "layer_name",
Color = System.Drawing.Color.White // or Color.FromArgb(255)
};
Is there any way to set ColorIndex to layer or polyline?
If not, do you have any idea to convert the white color to black when printing out?
Re: Set ColorIndex instead of RGB
Hello,
For your information, the color with index 7 indicates Black/White that means an object can be Black or White depending on the background color, these two colors are inverted when you change the background color from Black to White and vice versa. Unfortunately, CAD .NET doesn't allow to assign AutoCAD Color Index number to an entity or layer.
Mikhail
For your information, the color with index 7 indicates Black/White that means an object can be Black or White depending on the background color, these two colors are inverted when you change the background color from Black to White and vice versa. Unfortunately, CAD .NET doesn't allow to assign AutoCAD Color Index number to an entity or layer.
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Set ColorIndex instead of RGB
Thank you for your reply.
Anyway, I solved it in another way.
I hope it helps someone.
---------------------------------------------
1. Make a dwg file.
2. Add layers and choose ACI(Autocad Color Index) Colors for the layers
3. In code, load that .dwg file and copy the colors of layers
4. assign them to any colors of layers.
---------------------------------------------
Anyway, I solved it in another way.
I hope it helps someone.
---------------------------------------------
1. Make a dwg file.
2. Add layers and choose ACI(Autocad Color Index) Colors for the layers
3. In code, load that .dwg file and copy the colors of layers
4. assign them to any colors of layers.
---------------------------------------------
Code: Select all
public class ACIColorInfo
{
public int index = -1;
/// <summary>
/// Autocad Color Index String
/// </summary>
public string IndexStr
{
get => index.ToString();
set
{
int.TryParse(value, out index);
}
}
/// <summary>
/// Autocad Color Index
/// </summary>
public int Index { get => index; set => index = value; }
/// <summary>
/// Custom Color Name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Color
/// </summary>
public Color Color { get; set; }
}
Code: Select all
public Dictionary<int, ACIColorInfo> GetACIColors()
{
CADImage cadImageColorIndex = null;
try
{
string pathDWG = "ColorIndex.dwg"; // <= Change to your dwg file path
cadImageColorIndex = CADImage.CreateImageByExtension(pathDWG);
cadImageColorIndex.LoadFromFile(pathDWG);
Dictionary<int, ACIColorInfo> aciColorInfoDic = new Dictionary<int, ACIColorInfo>();
//
// ByLayer
//
aciColorInfoDic.Add(256, new ACIColorInfo() { index = 0, Name = "ByLayer", Color = DrawingColor.FromArgb(47, 255, 255, 255) });
//
// ByBlock
//
// hasn't been implemented yet
//
//
//
cadImageColorIndex.Converter.Layers.ForEach(entity =>
{
//
// "0" is default layer added automatically when creating a dwg file.
// However, Number '0' will be used as key of the ACI dictionary for ByLayer Color Type.
//
if (entity.EntName == "0") return;
ACIColorInfo aciColorInfo = new ACIColorInfo();
aciColorInfo.IndexStr = entity.EntName;
aciColorInfo.Name = entity.Color.Name;
aciColorInfo.Color = entity.Color;
aciColorInfoDic.Add(aciColorInfo.index, aciColorInfo);
});
return aciColorInfoDic;
}
catch (Exception ee)
{
TraceManager.AddLog(string.Format("{0}r\n{1}", ee.StackTrace, ee.Message));
System.Diagnostics.Debug.WriteLine(string.Format("{0}r\n{1}", ee.StackTrace, ee.Message));
return null;
}
finally
{
if (cadImageColorIndex != null)
{
cadImageColorIndex.ClearBuffer();
cadImageColorIndex.Dispose();
cadImageColorIndex = null;
}
GC.Collect();
}
}
Code: Select all
//
// Use
//
Dictionary<int, ACIColorInfo> aciColorInfoDic = GetACIColors();
Color colorByLayer = aciColorInfoDic.ContainsKey(256) ? aciColorInfoDic[256].Color : DrawingColor.White;
Color color_7 = aciColorInfoDic.ContainsKey(7) ? aciColorInfoDic[7].Color : colorByLayer;
//
// Assign to
//
yourLayer.Color = color_7;
Code: Select all
/// ACI Color Properties Info
///
/// Index | Name | ARGB | IsKnownColor | IsNamedColor | IsSystemColor |
/// ------|------------|-----------------|--------------|--------------|---------------|
/// 1 | Red | 255,255, 0, 0 | true | true | false |
/// 2 | Yellow | 255,255,255, 0 | true | true | false |
/// 3 | Lime | 255, 0,255, 0 | true | true | false |
/// 4 | Aqua | 255, 0,255,255 | true | true | false |
/// 5 | Blue | 255, 0, 0,255 | true | true | false |
/// 6 | Fuchsia | 255,255, 0,255 | true | true | false |
/// 7 | 536870911 | 0, 0, 0, 0 | false | true | false |
/// 8 | Gray | 255,128,128,128 | true | true | false |
/// 9 | Silver | 255,192,192,192 | true | true | false |
/// ...
/// 250 | ff333333 | 255, 51, 51, 51 | false | false | false |
/// 251 | ff565656 | 255, 91, 91, 91 | false | false | false |
/// ...
/// 255 | 4fffffff | 79,255,255,255 | false | false | false |
///
///
/// ByBlock
/// 0 |
/// ByLayer
/// 256 | 2fffffff | 47,255,255,255 | false | false | false |
- Attachments
-
- ColorIndex.zip
- (13.87 KiB) Downloaded 603 times