zoukankan      html  css  js  c++  java
  • AutoCAD 通过COM调用Preference设置背景颜色

    AutoCAD中访问系统设定Preference,需要调用COM API,添加 Autodesk.AutoCAD.Interop的引用:

    直接上代码: 

    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Interop;

    using System.Drawing;
     

            [CommandMethod("GetBkClr")]

            public void GetBkGndColor()

            {

                // Access the Preferences object

                AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

        

                uint clr = acPrefComObj.Display.GraphicsWinLayoutBackgrndColor ;

                ed.WriteMessage(UIntToColor(clr).ToString());

            }

     

            [CommandMethod("SetBKClr", CommandFlags.Session)]

            public void SetBkGroundColor()

            {

                // Access the Preferences object

                AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

     

                // Use the CursorSize property to set the size of the crosshairs

                acPrefComObj.Display.CursorSize = 100;

     

                System.Drawing.Color bkClr = Color.FromArgb(0, 255, 255, 255);//white, do not use known color, use Argb instead.

     

                //acPrefComObj.Display.GraphicsWinLayoutBackgrndColor = ColorToUInt(bkClr);

                acPrefComObj.Display.GraphicsWinModelBackgrndColor = ColorToUInt(bkClr);

     

            }

     

            private uint ColorToUInt(Color color)

            {

                return (uint)((color.A << 24) | (color.R << 16) |

                              (color.G << 8) | (color.B << 0));

            }

     

            private System.Drawing.Color UIntToColor(uint color)

            {

                byte a = (byte)(color >> 24);

                byte r = (byte)(color >> 16);

                byte g = (byte)(color >> 8);

                byte b = (byte)(color >> 0);

                return Color.FromArgb(a, r, g, b);

            }

    其中,转换函数来自 http://www.daniweb.com/software-development/csharp/code/217202

    作者:峻祁连
    邮箱:junqilian@163.com
    出处:http://junqilian.cnblogs.com
    转载请保留此信息。
  • 相关阅读:
    u-boot.lds分析
    u-boot的makefile中的一些目录的设定,以及涉及的shell,make语法。
    u-boot入门第一步,分析mkconfig
    uboot学习——Makefile里的echo使用!
    Linux下的打包与压缩和tar命令!
    关于undefined reference的问题
    JZ2440 编译Uboot1.1.6 undefined reference to ‘raise’
    POJ 1094 Sorting It All Out
    链式前向星
    Codeforces Round #197 (Div. 2) A~D
  • 原文地址:https://www.cnblogs.com/junqilian/p/2335861.html
Copyright © 2011-2022 走看看