Author Topic: Color lab  (Read 3843 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: [Select]
// Codehimbelonga kwb@theSwamp 20070211
// For AC2007: VS2005
//

#region usingdeclarations

using System;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
#endregion

#region usingAliases

// Shortcuts to the managed classes .. using the ObjectARX class prefixes
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcColors = Autodesk.AutoCAD.Colors;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;

using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcWindows = Autodesk.AutoCAD.Windows;
//
//
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

#endregion

[assembly: AcRx.CommandClass(typeof(kdubTestStuff.kdubColorLab))]

namespace kdubTestStuff
{
    /// <summary>
    /// Summary for kdubTestStuff
    /// </summary>
    public class kdubColorLab : AcRx.IExtensionApplication
    {
        /// <summary>
        /// ---------------------------------------------------------------------------------------------
        /// </summary>
        public void Initialize()
        {
            //Let the user know what's happening while loading your stuff 
            AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\nConcept Code For AC2007, MSVS2005 :: kwb@theSwamp 20070211 ->> ...");
            ed.WriteMessage("\nType CMD1   : Run Color Lab test\n");
        }
        /// ---------
        public void Terminate()
        {
            //Nothing to see here yet, move along !
        }
        /// <summary>
        /// ---------------------------------------------------------------------------------------------
        /// </summary>
        public kdubColorLab()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        [AcRx.CommandMethod("Cmd1")]
        static public void testColor()
        {
            AcWindows.ColorDialog clr = new AcWindows.ColorDialog();
            if (clr.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("Color was Not Selected", "Oooooops");
                return;               
            }

            if (clr.Color.IsByAci)
            {
                // get the RGB values of the Color.ColorIndex
                int colorIndex = clr.Color.ColorIndex;
                System.Byte colorByte = System.Convert.ToByte(colorIndex);
                int rgb = AcColors.EntityColor.LookUpRgb(colorByte);

                long b = (rgb & 0xffL);
                long g = (rgb & 0xff00L) >> 8;
                long r = rgb >> 16; ;

                // not really required for this sample ..       

                int ri = System.Convert.ToInt32(r);
                int gi = System.Convert.ToInt32(g);
                int bi = System.Convert.ToInt32(b);

                // Tell us about it !
                MessageBox.Show(                   
                     "Color is : " + clr.Color.ToString()
                    + "\nColor Index ToByte : " + colorByte.ToString()
                    + "\nTranslated RGB int : " + rgb.ToString()
                    + "\nTranslated R,G,B : " + ri.ToString() + "," + gi.ToString() + "," + bi.ToString()
                , "Color is by ACI");
            }
            else if (clr.Color.IsByLayer)
            {
                MessageBox.Show(
                    "Color Code is : " + clr.Color.ToString()
                    , "Color is By LAyer");
            }
            else if (clr.Color.IsByBlock)
            {               
                MessageBox.Show(                   
                     "Color Code is : " + clr.Color.ToString()
                    , "Color is By Block");
            }
            else if (clr.Color.HasBookName)
            {
                MessageBox.Show(
                    "Color Code is : " + clr.Color.ToString()
                    + "\n To RGB : "
                    + clr.Color.Red.ToString()
                    + "," + clr.Color.Green.ToString()
                    + "," + clr.Color.Blue.ToString()
                    , "Color Has Book Name"
                    );
            }
            else
            {
                MessageBox.Show(
                    "Color Code is : " + clr.Color.ToString()
                    + "\n To RGB : "
                    + clr.Color.Red.ToString()
                    + "," + clr.Color.Green.ToString()
                    + "," + clr.Color.Blue.ToString()
                    , "Color is True Color"
                    );
            }
        }
    }
}

Pictures follow : < not visible to guests >

« Last Edit: February 12, 2007, 04:59:48 AM by Kerry Brown »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
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  :-)
Me

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.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--