using System;
using System.Runtime.InteropServices;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcCl = Autodesk.AutoCAD.Colors;
[assembly: CommandClass(typeof(Rivilis.ColorConv))]
namespace Rivilis
{
public class ColorConv
{
public static int MediaColorToColorIndex(System.Windows.Media.Color clm)
{
return AcCl.EntityColor.LookUpAci(clm.R, clm.G, clm.B);
}
public static System.Windows.Media.Color ColorIndexToMediaColor(int cla)
{
int acirgb = AcCl.EntityColor.LookUpRgb((byte)cla);
byte b = (byte)(acirgb);
byte g = (byte)(acirgb >> 8);
byte r = (byte)(acirgb >> 16);
return System.Windows.Media.Color.FromRgb(r, g, b);
}
[CommandMethod("ClsConv")]
public void ClsConv()
{
AcEd.Editor ed =
AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
System.Windows.Media.Color clm =
System.Windows.Media.Color.FromRgb(/*R*/ 0, /*G*/ 255, /*B*/ 63);
// Преобразуем System.Windows.Media.Color в Autodesk.AutoCAD.Colors.Color
AcCl.Color cla = AcCl.Color.FromColor(clm);
ed.WriteMessage("\nAutodesk.AutoCAD.Colors.Color = {0}", cla);
// Получаем индексный цвет
int iColorIndex = MediaColorToColorIndex(clm);
ed.WriteMessage("\nColorIndex = {0}", iColorIndex);
// Выполним обратное преобразование
clm = ColorIndexToMediaColor(iColorIndex);
ed.WriteMessage("\nSystem.Windows.Media.Color = {0},{1},{2}", clm.R, clm.G, clm.B);
}
}
}