Author Topic: get autocad UI current colors  (Read 8529 times)

0 Members and 1 Guest are viewing this topic.

nekitip

  • Guest
get autocad UI current colors
« on: September 18, 2014, 05:28:21 AM »
I can't find where is current autocad UI colors list.
What I would like to do is a way to change my own pallete background depending on current color of, say, acad properties pallete. Easy thing, but I just can't find where that list is.
Closest I have google is to http://adndevblog.typepad.com/autocad/2013/05/wpf-databinding-to-the-commandline-colors.html, but...

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: get autocad UI current colors
« Reply #1 on: September 18, 2014, 05:38:32 AM »
In 2015, there is a system variable. You could set an event to see when it is changing.

Before 2015, you need to read the Registry (current Profile) to find out if the light or dark theme is active.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

nekitip

  • Guest
Re: get autocad UI current colors
« Reply #2 on: September 18, 2014, 05:58:47 AM »
Well, I have found some list, but i don't know how to iterate.
It seems it returns items by name (and name I don't know), and from that link, I choose one to see if this works.
Code - vb.net: [Select]
  1. Dim col = Autodesk.AutoCAD.ApplicationServices.Application.UIBindings.ColorSettings
  2. Dim c1 = col.Item("CommandLineBackground")

But, huiz, are you saying it is only possible for (properties pallete) to be dark or light?
If that is so, than this may do for me. Then only thing left is to find out what version of autocad is running, since 2013,2014 have different colors from 2015 (and the only last 3 I need)

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: get autocad UI current colors
« Reply #3 on: September 18, 2014, 06:11:46 AM »
Ah you need the color of the Palette!

AutoCAD only shows the Light or Dark Theme setting. And since 2015 you can do that with a system variable GetSystemVariable("COLORTHEME") which is set to 0 or 1. In previous versions you need to read the current Profile from the Registry.

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R19.1\ACAD-D001:409\Profiles

and then under that Profile you can find somewhere the setting if the user uses the light theme or the dark theme.

You won't get the real color but you can find out with a screenshot and use Photoshop or something to get the dialog color.

For more information you can visit http://through-the-interface.typepad.com/through_the_interface/2014/04/supporting-autocad-2015s-dark-theme.html

The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: get autocad UI current colors
« Reply #4 on: September 18, 2014, 06:15:33 AM »
I played a bit with this too but found out that

1. It takes a lot of programming to change all the dialogs, Palettes and other stuff
2. Dark theme color in 2015 is a different color than dark theme in 2014
3. Some Windows Form objects like Groupboxes are ugly with a dark background
4. Some colors like green are really ugly (and my application main color is green)
5. AutoCAD and certainly Civil3D don't use the dark color for their dialogs, only the Properties Palette and the Layer Palette (and some other)

So, I just keep things simple and don't check the Dark Theme setting at all.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

nekitip

  • Guest
Re: get autocad UI current colors
« Reply #5 on: September 18, 2014, 10:57:15 AM »
well, I have settled with folowing code, so if it helps, I share here the code to dynamically change a few colors depending on the current theme in autocad (dark, or light)
in WPF
-if it is under autocad 2015, it considers light theme always
-if it is autocad 2015 or later, change colors depending on theme.
add handler
Code - vb.net: [Select]
  1. AddHandler Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged, AddressOf variableChanged
react to variable change
Code - vb.net: [Select]
  1. Private Sub variableChanged(ByVal o As Object, e As Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs)
  2.             If e.Name = "COLORTHEME" AndAlso e.Changed Then
  3.                 checkTheme()
  4.             End If
  5.         End Sub
also after starting everything, check for the first time (have instantiated colors somewhere)
Code - vb.net: [Select]
  1.         Private Sub checkTheme()
  2.             If Autodesk.AutoCAD.ApplicationServices.Application.Version.Major > 19 Then
  3.                 If CShort(Application.GetSystemVariable("COLORTHEME")) = 1 Then
  4.                     colors.activeIs("light")
  5.                 Else
  6.                     colors.activeIs("dark")
  7.                 End If
  8.             End If
  9.         End Sub

define this somwhere to bind this to WPF
Code - vb.net: [Select]
  1.  Private Shared _colors As New colorBackground
  2.         Public Shared Property colors As colorBackground
  3.             Get
  4.                 Return _colors
  5.             End Get
  6.             Set(value As colorBackground)
  7.                 _colors = value
  8.             End Set
  9.         End Property

and the class where you define your colors
Code - vb.net: [Select]
  1. Public Class colorBackground
  2.         Implements INotifyPropertyChanged
  3.         Public Class colorset
  4.             Private _name As String = ""
  5.             Private _color1 As String = ""
  6.             Private _color2 As String = ""
  7.             Private _color3 As String = ""
  8.  
  9.             Sub New()
  10.  
  11.             End Sub
  12.  
  13.             Sub New(ByVal colorsetName As String, ByVal color1 As String, ByVal color2 As String, ByVal color3 As String)
  14.                 _name = colorsetName
  15.                 _color1 = color1
  16.                 _color2 = color2
  17.                 _color3 = color3
  18.             End Sub
  19.  
  20.             Public ReadOnly Property colorsetName As String
  21.                 Get
  22.                     Return _name
  23.                 End Get
  24.             End Property
  25.  
  26.             Public ReadOnly Property color1 As String
  27.                 Get
  28.                     Return _color1
  29.                 End Get
  30.             End Property
  31.             Public ReadOnly Property color2 As String
  32.                 Get
  33.                     Return _color2
  34.                 End Get
  35.             End Property
  36.             Public ReadOnly Property color3 As String
  37.                 Get
  38.                     Return _color3
  39.                 End Get
  40.             End Property
  41.  
  42.         End Class
  43.         Private _active As colorset
  44.         Private _list As New List(Of colorset)
  45.  
  46.         Sub New()
  47.             _list.Add(New colorset("light", "#FFF0F0F0", "#FFF0F0F0", "White"))          
  48.             _list.Add(New colorset("dark", "Transparent", "Pink", "WhiteSmoke"))
  49.             _active = _list(0)
  50.         End Sub
  51.  
  52.         Public Sub activeIs(ByVal theme As String)
  53.             For Each c As colorset In _list
  54.                 If c.colorsetName = theme Then active = c
  55.             Next
  56.         End Sub
  57.  
  58.         Public Property active As colorset
  59.             Get
  60.                 Return _active
  61.             End Get
  62.             Set(value As colorset)
  63.                 _active = value
  64.                 OnPropertyChanged(New PropertyChangedEventArgs("active"))
  65.             End Set
  66.         End Property
  67.  
  68.         Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
  69.             If Not PropertyChangedEvent Is Nothing Then
  70.                 RaiseEvent PropertyChanged(Me, e)
  71.             End If
  72.         End Sub
  73.  
  74.         Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
  75.     End Class

and now you have three colors for the parts you care the most to change if user changes theme to dark in 2015
improve this as you wish

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: get autocad UI current colors
« Reply #6 on: February 28, 2016, 05:32:20 AM »
I'm still getting to the bottom of this but it's all in the installation DLLs (duh), in particular AcWindows.dll and AdUiPalettes.dll - you can trace the chain from Acmgd.dll, load that and follow the References. In this case we're looking for the Resources inside the DLLs

Here is AdUiPalettes.dll...

See those last two themes - that's them. If you DIFF them it starts to make sense, in a HSBColor kind of way..

I have found the best a good (free) decompiler is dnSpy - you can download a pre-built release or build it yourself. Jetbrains dotpeek  and Telerik Decompile are both good too. You should try all 3 on the same code and see the differences, it is quite interesting where they vary, particularly on things like C#6, Reactive Extensions, Events (some just decompile the code as Delegates).

Before the panic hits the streets about "hacking" etc, note that decompiling these DLLs is officially sanctioned, nay - encouraged, by the ADN ... http://adndevblog.typepad.com/autocad/2012/08/a-rich-source-of-autocad-net-sample-code.html & http://through-the-interface.typepad.com/through_the_interface/2010/02/debugging-into-autocads-net-api-layer-using-reflector-part-1.html

Before you decompile it and copy-paste the XAML (erm, ethically questionable) note that it has already been mentioned the colors changed between 2014 and 2015. So, perhaps it is a better idea to use the resources in that DLL (with a fallback position, of course). See the links below to get the ball rolling in that.

ok, I have to get back to work ...

Research notes for me (when I have more time on my hands), and anyone else who is interested ...

http://stackoverflow.com/a/2771208/492

https://www.google.com.au/search?safe=active&q=.net+ResourceManager+baml

https://msdn.microsoft.com/en-us/library/system.resources.resourcemanager(v=vs.110).aspx

https://books.google.com.au/books?id=b1n3mOfdsBoC&pg=PA60&lpg=PA60&dq=.net+ResourceManager+baml&source=bl&ots=AfaJ4o1Rgn&sig=EmU8-WxZZVKRwH4BHEm77QokB5U&hl=en&sa=X&ved=0ahUKEwjAy6LMmprLAhVDmJQKHU5ICiMQ6AEIHDAA#v=onepage&q=.net%20ResourceManager%20baml&f=false
« Last Edit: March 01, 2016, 04:04:36 AM by CADbloke »

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: get autocad UI current colors
« Reply #7 on: February 29, 2016, 07:14:48 PM »
Have a look into this https://github.com/ADN-DevTech/AutoCAD-Slide-Library-Manager to see how to use Themes that are embedded inside a DLL, in this case it's a Maya theme but the principle is the same.

See also https://github.com/ADN-DevTech/Maya-Net-Wpf-DarkScheme . Note, linking to an existing DLL to get the theme may not work if that DLL is not in the same palce as your executable / AutoCAD / lost socks. I haven't tested any of this.
« Last Edit: February 29, 2016, 07:19:41 PM by CADbloke »

Steve Hill

  • Mosquito
  • Posts: 5
Re: get autocad UI current colors
« Reply #8 on: September 09, 2021, 03:46:35 PM »
Thanks to you all for your posts on this, I was able to figure out a working solution that is dynamic to the Application theme colors, light or dark.

Ultimately, my issue was in using WPF, even the the User Control background was transparent, it did not show up correctly within the palette.

When using AddVisual("MyPalette", Palette, true), it actually came in Black.

Then I ran across this blog stating we should host the WPF with ElementHost to get it to come in properly. That came in, but did not change colors based on the theme.

https://through-the-interface.typepad.com/through_the_interface/2009/08/hosting-wpf-content-inside-an-autocad-palette.html

That brought me here to determine a dynamic solution that works across various versions (2015 and up) that pulls in the theme color. To use this solution, you only need to add reference to AdUiPalettes.dll. Thanks to @CADBLOKE for the idea of using DotPeek to look into these assemblies I was able to determine that Autodesk.Windows.Palettes.PaletteThemeDefaults.DarkOverallColor would return the Dark theme color and Autodesk.Windows.Palettes.PaletteThemeDefaults.LightOverallColor would return the light theme. And thanks to @nekitip as I used parts of your code converted over to C#.

Code: [Select]
    public class PaletteSetItem : PaletteSet
    {
        static PaletteSetItem instance = null;
        static Guid guid = new Guid("{f9fead11-f73b-48b3-84c2-bd93b02df9bc}");
        const string showCommand = "MyPalette";
        private SolidColorBrush backgroundColor; //this is used to store the palette background color if needed

        public static MyPalette MyPaletteCtrl { get; set; }

        public PaletteSetItem()
            : base(showCommand, showCommand, guid)
        {
            try
            {
                //Add the icon to the palette
                base.Icon = MyIcon;

                //Set the Palette size.
                base.Size = new Size(400, 800);

                //Changing background color based on System variable
                //Following ideas here: https://www.theswamp.org/index.php?topic=47877.0
                //Using Jetbrains DotPeek on AdUiPalettes was able to identify and pull the PaletteThemeDefaults
                //Then converting color to a brush
                MyPaletteCtrl = new MyPalette();
 
                //Check theme to set the initial color and the reactors
                CheckTheme();

                //Set Palette background color
                MyPaletteCtrl.Background = backgroundColor;

                //Add the palette
                base.AddVisual("MyPalette", MyPaletteCtrl, true);
                Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
            }
            catch (Exception ex)
            {
                //Error loading palette
            }
        }

        protected override void OnPaletteSetClosed()
        {
               Application.SystemVariableChanged -= new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
        }

        public static void PaletteSetItemCommand()
        {
            instance = new PaletteSetItem();

            instance.Visible = true;
        }

        private void variableChanged(object o, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
        {
            if (e.Name == @"COLORTHEME" && e.Changed)
                CheckTheme();

            //Set Palette background color
            MyPaletteCtrl.Background = backgroundColor;
        }

        private void CheckTheme()
        {
            if (Application.Version.Major > 19)
            {
                //Background color is set based on the theme color
                                if (System.Convert.ToInt32(Application.GetSystemVariable(@"COLORTHEME")) == 1)
                {
                    Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.LightOverallColor);
                    backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
                }
                else
                {
                    Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.DarkOverallColor);
                    backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
                }
            }
            else
            {
                //Sets a default gray color just so there's something
                backgroundColor = (SolidColorBrush)new BrushConverter().ConvertFrom(@"#808080");
            }
        }

    }




Of course, you could likely set this up to bind to the WPF User Control, but I chose not to go that route as I think this is more supportive of both WinForms and WPF.

Hope this helps someone else too.

« Last Edit: September 14, 2021, 10:56:53 PM by Steve Hill »

Lonnie

  • Newt
  • Posts: 169
Re: get autocad UI current colors
« Reply #9 on: September 09, 2021, 06:28:07 PM »
I don't know if this is on target or not.
I had to change a bunch of color pallets with lisp. Here is how I went about it.

I ended up finding what I wanted to change with this.

(vlax-dump-object (vla-get-display (vla-get-preferences (vlax-get-Acad-object))) T

I then sorted out what colors I wanted to change.

as another aside.

(vlax-dump-object (vla-get-preferences (vlax-get-Acad-object)) T)


Will give you Option Tab names to drill down and find what you need.

I ended up with this for my what I needed to change.

Code: [Select]
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
(setq acaddisp (vlax-get-property acadpref 'display))
(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 65986) ;;Model space background
(vlax-put-property acaddisp 'GraphicsWinLayoutBackgrndColor  63434) ;;command area
(vlax-put-property acaddisp 'ModelCrosshairColor 865785);; crosshairs
(vlax-put-property acaddisp 'TextWinBackgrndColor 3687) ;;command area