Author Topic: Color lab  (Read 6364 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Color lab
« on: February 11, 2007, 08:03:52 AM »
Had a play with colors this afternoon ..
Code - C#: [Select]
  1. // Codehimbelonga kwb@theSwamp 20070211
  2. // For AC2007: VS2005
  3. //
  4.  
  5. #region usingdeclarations
  6.  
  7. using System;
  8. using System.Windows.Forms;
  9.  
  10. using Autodesk.AutoCAD.ApplicationServices;
  11. using Autodesk.AutoCAD.Colors;
  12. #endregion
  13.  
  14. #region usingAliases
  15.  
  16. // Shortcuts to the managed classes .. using the ObjectARX class prefixes
  17. using AcAp = Autodesk.AutoCAD.ApplicationServices;
  18. using AcColors = Autodesk.AutoCAD.Colors;
  19. using AcDb = Autodesk.AutoCAD.DatabaseServices;
  20. using AcEd = Autodesk.AutoCAD.EditorInput;
  21. using AcGe = Autodesk.AutoCAD.Geometry;
  22. using AcGi = Autodesk.AutoCAD.GraphicsInterface;
  23.  
  24. using AcLy = Autodesk.AutoCAD.LayerManager;
  25. using AcPl = Autodesk.AutoCAD.PlottingServices;
  26. using AcRx = Autodesk.AutoCAD.Runtime;
  27. using AcWindows = Autodesk.AutoCAD.Windows;
  28. //
  29. //
  30. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  31.  
  32. #endregion
  33.  
  34. [assembly: AcRx.CommandClass(typeof(kdubTestStuff.kdubColorLab))]
  35.  
  36. namespace kdubTestStuff
  37. {
  38.     /// <summary>
  39.     /// Summary for kdubTestStuff
  40.     /// </summary>
  41.     public class kdubColorLab : AcRx.IExtensionApplication
  42.     {
  43.         /// <summary>
  44.         /// ---------------------------------------------------------------------------------------------
  45.         /// </summary>
  46.         public void Initialize()
  47.         {
  48.             //Let the user know what's happening while loading your stuff  
  49.             AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  50.  
  51.             ed.WriteMessage("\nConcept Code For AC2007, MSVS2005 :: kwb@theSwamp 20070211 ->> ...");
  52.             ed.WriteMessage("\nType CMD1   : Run Color Lab test\n");
  53.         }
  54.         /// ---------
  55.         public void Terminate()
  56.         {
  57.             //Nothing to see here yet, move along !
  58.         }
  59.         /// <summary>
  60.         /// ---------------------------------------------------------------------------------------------
  61.         /// </summary>
  62.         public kdubColorLab()
  63.         {
  64.             //
  65.             // TODO: Add constructor logic here
  66.             //
  67.         }
  68.         [AcRx.CommandMethod("Cmd1")]
  69.         static public void testColor()
  70.         {
  71.             AcWindows.ColorDialog clr = new AcWindows.ColorDialog();
  72.             if (clr.ShowDialog() != System.Windows.Forms.DialogResult.OK)
  73.             {
  74.                 MessageBox.Show("Color was Not Selected", "Oooooops");
  75.                 return;                
  76.             }
  77.  
  78.             if (clr.Color.IsByAci)
  79.             {
  80.                 // get the RGB values of the Color.ColorIndex
  81.                 int colorIndex = clr.Color.ColorIndex;
  82.                 System.Byte colorByte = System.Convert.ToByte(colorIndex);
  83.                 int rgb = AcColors.EntityColor.LookUpRgb(colorByte);
  84.  
  85.                 long b = (rgb & 0xffL);
  86.                 long g = (rgb & 0xff00L) >> 8;
  87.                 long r = rgb >> 16; ;
  88.  
  89.                 // not really required for this sample ..        
  90.  
  91.                 int ri = System.Convert.ToInt32(r);
  92.                 int gi = System.Convert.ToInt32(g);
  93.                 int bi = System.Convert.ToInt32(b);
  94.  
  95.                 // Tell us about it !
  96.                 MessageBox.Show(                    
  97.                      "Color is : " + clr.Color.ToString()
  98.                     + "\nColor Index ToByte : " + colorByte.ToString()
  99.                     + "\nTranslated RGB int : " + rgb.ToString()
  100.                     + "\nTranslated R,G,B : " + ri.ToString() + "," + gi.ToString() + "," + bi.ToString()
  101.                 , "Color is by ACI");
  102.             }
  103.             else if (clr.Color.IsByLayer)
  104.             {
  105.                 MessageBox.Show(
  106.                     "Color Code is : " + clr.Color.ToString()
  107.                     , "Color is By LAyer");
  108.             }
  109.             else if (clr.Color.IsByBlock)
  110.             {                
  111.                 MessageBox.Show(                    
  112.                      "Color Code is : " + clr.Color.ToString()
  113.                     , "Color is By Block");
  114.             }
  115.             else if (clr.Color.HasBookName)
  116.             {
  117.                 MessageBox.Show(
  118.                     "Color Code is : " + clr.Color.ToString()
  119.                     + "\n To RGB : "
  120.                     + clr.Color.Red.ToString()
  121.                     + "," + clr.Color.Green.ToString()
  122.                     + "," + clr.Color.Blue.ToString()
  123.                     , "Color Has Book Name"
  124.                     );
  125.             }
  126.             else
  127.             {
  128.                 MessageBox.Show(
  129.                     "Color Code is : " + clr.Color.ToString()
  130.                     + "\n To RGB : "
  131.                     + clr.Color.Red.ToString()
  132.                     + "," + clr.Color.Green.ToString()
  133.                     + "," + clr.Color.Blue.ToString()
  134.                     , "Color is True Color"
  135.                     );
  136.             }
  137.         }
  138.     }
  139. }

Pictures follow : < not visible to guests >

« Last Edit: December 24, 2023, 10:17:59 PM by kdub_nz »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Color lab
« Reply #1 on: February 11, 2007, 08:11:25 AM »
That's got a fairly high C.F.I (Coolness Factor Index) there Kerry  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Color lab
« Reply #2 on: February 11, 2007, 08:14:17 AM »
That's got a fairly high C.F.I (Coolness Factor Index) there Kerry  :-)

Thanks Glenn

it was sortof fun ... balances out the tedious RTFM I went through.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.