• 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
    转载请保留此信息。
  • 相关阅读:
    Centos 7 下安装LDAP 双主同步
    Apache Ranger && HDFS
    Java 学习(六)
    Java学习(五)
    Java学习(四)
    Java学习(三)
    Java学习(二)
    Java学习(一)
    css笔记
    磁盘性能测试方法
  • 原文地址:https://www.cnblogs.com/junqilian/p/2335861.html
Copyright © 2020-2023  润新知