Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McCMColor

Class: McCmColor ​

2d.McCmColor

McCMColor is a color object in CAD, used to uniformly represent color values and color indexes, and provide basic color data for entity attribute settings.

Description

This class is used for color management of graphic objects, which can set the true color through RGB values or control color modes such as layer by layer and block by color index. It can accomplish: -Create and copy color objects; -Set 'RGB' or color index; -Read color strings/styles; -Apply colors to the 'trueColor' or 'colorIndex' properties of entity objects.

Usage:

  1. Construct an instance of McCMColor;
  2. Assign values through setRGB() or colorIndex;
  3. Assign color attributes to objects to entities;
  4. Read color strings, styles, or object color values when needed.

Summary: In practical development, McCMColor is the basic type of entity color control, suitable for scenes such as layer color, object color, and interface color display.

Example

ts
import { McCmColor, McDbEntity } from "mxcad";

//Create color objects and apply them to entity colors.
async function testColor() {
  const ent = new McDbEntity();
  ent.trueColor = new McCmColor(255, 0, 0);

  const color = new McCmColor();
  color.setRGB(0, 255, 0);
Console.log ("color string:", color. getColorString());
}

Table of contents ​

Constructors ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McCmColor(red?, green?, blue?, n?)

Constructor. Set RGB values.

Parameters ​

NameTypeDescription
red? number \object
green? numberGreen (0-255)
blue? numberBlue (0-255)
N?numberTransparency (0-255)

Accessors ​

blue ​

• get blue(): number

Get or set the blue value in RGB, and set the numerical range from 0 to 255.

Returns ​

number

• set blue(val): void

Parameters ​

NameType
valnumber

Returns ​

void


colorIndex ​

• get colorIndex(): number

Get or set color index.

Returns ​

number

Example

ts
import { McCmColor, ColorIndexType } from "mxcad"

const color = new McCmColor();
color.colorIndex = ColorIndexType.kBylayer;// Set color to follow layers
console.log(color.colorIndex);

• set colorIndex(val): void

Parameters ​

NameType
valnumber

Returns ​

void


green ​

• get green(): number

Get or set the green value in RGB, and set the numerical range to 0-255.

Returns ​

number

• set green(val): void

Parameters ​

NameType
valnumber

Returns ​

void


method ​

• get method(): number

method.

Returns ​

number

• set method(val): void

Parameters ​

NameType
valnumber

Returns ​

void


n ​

• get n(): number

Get or set the color transparency, with a numerical range of 0-255. 0 completely transparent, 160 semi transparent (median), 255 completely opaque

Returns ​

number

• set n(val): void

Parameters ​

NameType
valnumber

Returns ​

void


red ​

• get red(): number

Get or set the red value in RGB, and set the numerical range from 0 to 255.

Returns ​

number

• set red(val): void

Parameters ​

NameType
valnumber

Returns ​

void

Methods ​

clone ​

▸ clone(): McCmColor

Kelon, a color object

Returns ​

McCmColor

Return the cloned color object


copy ​

▸ copy(val): McCmColor

Copy the value of a color object.

Parameters ​

NameTypeDescription
Val[McCMColor] (2d. McCmColor. md)Color Object

Returns ​

McCmColor

Example

ts
import { McCmColor } from "mxcad"

const color:McCmColor = new McCmColor();
const red_color:McCmColor = new McCmColor(255, 0, 0);
color.copy(red_color);

getColorString ​

▸ getColorString(): string

Obtain color description string

Returns ​

string

Color description string


getColorValue ​

▸ getColorValue(layerId?, blkRefId?): string

Obtain a color value string in hexadecimal format, layerId: The color will take the color of the layer pointed to by layerId when changing layers, blkRefId: When the color follows the block, the block color pointed to by blkRefId will be taken

Parameters ​

NameTypeDescription
layerId?[McObjectid] (2d. McObjectid. md)Layer ID
blkRefId?[McObjectid] (2d. McObjectid. md)Block record ID

Returns ​

string

Color value string


getImp ​

▸ getImp(): any

Retrieve internal implementation objects

Returns ​

any

Internal implementation object


getStyle ​

▸ getStyle(): string

Get CSS color styles such as RGB (0,0,0)

Returns ​

string


setColorIndex ​

▸ setColorIndex(colorIndex): void

Set color index and set color type based on the color index value.

Parameters ​

NameTypeDescription
ColorIndexNumberColor Index

Returns ​

void

Example

ts
import { McCmColor, ColorIndexType } from "mxcad"

const color = new McCmColor();
color.setColorIndex(ColorIndexType.kBylayer);// Set color to follow layers

setRGB ​

▸ setRGB(red, green, blue): void

Set RGB values.

Parameters ​

NameTypeDescription
RedNumberRed value
GreenNumberGreen value
BlueNumberBlue value

Returns ​

void