AutoCAD 2012 帮助
 
Make a color current through the database
 
 
 

This example sets a color current through the Database object with the Cecolor property.

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Colors
 
<CommandMethod("SetColorCurrent")> _
Public Sub SetColorCurrent()
  '' Get the current document
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
 
  '' Set the current color
  acDoc.Database.Cecolor = Color.FromColorIndex(ColorMethod.ByLayer, 256)
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
 
[CommandMethod("SetColorCurrent")]
public static void SetColorCurrent()
{
  // Get the current document
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  // Set the current color
  acDoc.Database.Cecolor = Color.FromColorIndex(ColorMethod.ByLayer, 256);
}

Work with Colors
Assign a color value to an object
Make a color current through the database
Make a color current with the CECOLOR system variable