Skip to content
On this page

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

Class: McCmColor

2d.McCmColor

Representing a color object, colors can be set through color indices or RGB values.

Example

ts
import { McCmColor, McDbEntity} from "mxcad";
//Set object color
  const ent = new McDbEntity();
  const color = new McCmColor(255,0,0);
  ent.trueColor = color;
ts
import { McCmColor, McDbEntity} from "mxcad";
//Modify object color
  async function Mx_Test_ChangeColor() {
//Select annotation object
    let getEntity = new MxCADUiPrEntity();
GetEntity. setMessage ("Select Annotation Object");
    let id = await getEntity.go();
    if (!id.isValid()) return;

let ent = id.getMcDbEntity();//  Get the target McDbEntity object
    if (!ent) return;
ent.trueColor = new McCmColor(255, 0, 255);//  Modify object color
  }

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
blue?` NumberBlue
n?number-

Example

ts
import { McCmColor } from "mxcad"

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

const colorObj = { red:0, green:255, blue:0};
const green_color:McCmColor = new McCmColor(colorObj);

Accessors

blue

get blue(): number

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

Returns

number

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
color.blue = 188;
console.log(color.blue)

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

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
color.green = 188;
console.log(color.green)

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

n

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

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
color.red = 188;
console.log(color.red)

set red(val): void

Parameters

NameType
valnumber

Returns

void

Methods

clone

clone(): McCmColor

Kelon, a color object

Returns

McCmColor

Return the cloned color object

Example

ts
import { McCmColor } from "mxcad"

const red_color:McCmColor = new McCmColor(255, 0, 0);
const copy_color:McCmColor = red_color.clone();

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

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
const str = color.getColorString();
console.log(str);

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

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
const val = color.getColorValue();
console.log(val);

getImp

getImp(): any

Retrieve internal implementation objects

Returns

any

Internal implementation object

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
const imp = color.getImp();

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

Example

ts
import { McCmColor } from "mxcad"

const color = new McCmColor();
color.setRGB(255,0,0);// red