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
    转载请保留此信息。
  • 相关阅读:
    Errors
    fix eclipse gc overhead limit exceeded in mac
    Cobub Razor
    Mac commands
    git vs svn
    SourceTree
    生成静态页技术
    URL重写技术总结
    回味手写三层-增删改查
    生成 (web): 找不到目标 .NET Framework 版本的引用程序集;请确保已安装这些程序集或选择有效的目标版本。
  • 原文地址:https://www.cnblogs.com/junqilian/p/2335861.html
Copyright © 2011-2022 走看看