[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
import { McCmColor, McDbEntity} from "mxcad";
//Set object color
const ent = new McDbEntity();
const color = new McCmColor(255,0,0);
ent.trueColor = color;
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
Name | Type | Description |
---|---|---|
red? | Number \ | object |
green? | Number | Green |
blue? | ` Number | Blue |
n? | number | - |
Example
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
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.blue = 188;
console.log(color.blue)
• 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
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.green = 188;
console.log(color.green)
• 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
n
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
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.red = 188;
console.log(color.red)
• 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
Example
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
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
Example
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
Name | Type | Description |
---|---|---|
layerId? | [McObjectid ] (2d. McObjectid. md) | Layer ID |
blkRefId? | [McObjectid ] (2d. McObjectid. md) | Block record ID |
Returns
string
Color value string
Example
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
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
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 layers
setRGB
▸ 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
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.setRGB(255,0,0);// red