[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:
- Construct an instance of McCMColor;
- Assign values through
setRGB()orcolorIndex; - Assign color attributes to objects to entities;
- 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
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
| Name | Type | Description |
|---|---|---|
red? | number \ | object |
green? | number | Green (0-255) |
blue? | number | Blue (0-255) |
| N? | number | Transparency (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
| Name | Type |
|---|---|
val | number |
Returns
void
colorIndex
• get colorIndex(): number
Get or set color index.
Returns
number
Example
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
| Name | Type |
|---|---|
val | number |
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
| Name | Type |
|---|---|
val | number |
Returns
void
method
• get method(): number
method.
Returns
number
• set method(val): void
Parameters
| Name | Type |
|---|---|
val | number |
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
| Name | Type |
|---|---|
val | number |
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
| Name | Type |
|---|---|
val | number |
Returns
void
Methods
clone
▸ clone(): McCmColor
Kelon, a color object
Returns
Return the cloned color object
copy
▸ copy(val): McCmColor
Copy the value of a color object.
Parameters
| Name | Type | Description |
|---|---|---|
| Val | [McCMColor] (2d. McCmColor. md) | Color Object |
Returns
Example
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
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
| ColorIndex | Number | Color Index |
Returns
void
Example
import { McCmColor, ColorIndexType } from "mxcad"
const color = new McCmColor();
color.setColorIndex(ColorIndexType.kBylayer);// Set color to follow layerssetRGB
▸ setRGB(red, green, blue): void
Set RGB values.
Parameters
| Name | Type | Description |
|---|---|---|
| Red | Number | Red value |
| Green | Number | Green value |
| Blue | Number | Blue value |
Returns
void
