AutoCAD uses COM to call Preference to set the background color

Source: Internet
Author: User

To access the system setting Preference in AutoCAD, you must call the com api to add a reference to Autodesk. AutoCAD. Interop:

 

Directly run the Code:

 

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 );

}

 

 

Where the conversion function comes from the http://www.daniweb.com/software-development/csharp/code/217202

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.