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.
---------------------------------------------
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 |

- ColorIndex.dwg.PNG (37.91 KiB) Viewed 8154 times