mxcad_2d API 文档 / 2d / McCmColor
Class: McCmColor
2d.McCmColor
表示一个颜色对象,可以通过颜色索引或 RGB 值来设置颜色。
Example
import { McCmColor, McDbEntity} from "mxcad";
//设置对象颜色
const ent = new McDbEntity();
const color = new McCmColor(255,0,0);
ent.trueColor = color;import { McCmColor, McDbEntity} from "mxcad";
// 修改对象颜色
async function Mx_Test_ChangeColor() {
// 选择标注对象
let getEntity = new MxCADUiPrEntity();
getEntity.setMessage("选择标注对象");
let id = await getEntity.go();
if (!id.isValid()) return;
let ent = id.getMcDbEntity();// 获取目标McDbEntity对象
if (!ent) return;
ent.trueColor = new McCmColor(255, 0, 255);// 修改对象颜色
}Table of contents
Constructors
Accessors
Methods
Constructors
constructor
• new McCmColor(red?, green?, blue?)
构造函数。设置 RGB 值。
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);Parameters
| Name | Type | Description |
|---|---|---|
red? | number | object | 红 |
green? | number | 绿 |
blue? | number | 蓝 |
Accessors
blue
• get blue(): number
获取或设置rgb值中的蓝色值,设置数值范围0~255。
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.blue = 188;
console.log(color.blue)Returns
number
• set blue(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
colorIndex
• get colorIndex(): number
获取或设置颜色索引。
Example
import { McCmColor, ColorIndexType } from "mxcad"
const color = new McCmColor();
color.colorIndex = ColorIndexType.kBylayer;//设置颜色随层
console.log(color.colorIndex);Returns
number
• set colorIndex(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
green
• get green(): number
获取或设置rgb值中的绿色值,设置数值范围0~255。
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.green = 188;
console.log(color.green)Returns
number
• set green(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
method
• get method(): number
方法。
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
获取或设置rgb值中的红色值,设置数值范围0~255。
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.red = 188;
console.log(color.red)Returns
number
• set red(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
Methods
clone
▸ clone(): McCmColor
刻隆一个颜色对象
Example
import { McCmColor } from "mxcad"
const red_color:McCmColor = new McCmColor(255, 0, 0);
const copy_color:McCmColor = red_color.clone();Returns
返回克隆后的颜色对象
copy
▸ copy(val): McCmColor
复制颜色对象的值。
Example
import { McCmColor } from "mxcad"
const color:McCmColor = new McCmColor();
const red_color:McCmColor = new McCmColor(255, 0, 0);
color.copy(red_color);Parameters
| Name | Type | Description |
|---|---|---|
val | McCmColor | 颜色对象 |
Returns
getColorString
▸ getColorString(): string
得到颜色说明字符串
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
const str = color.getColorString();
console.log(str);Returns
string
颜色说明字符串
getColorValue
▸ getColorValue(layerId?, blkRefId?): string
得到颜色值字符串,十六进制格式,layerId:颜色随层时会取layerId指向的层颜色,blkRefId:颜色随块时,会取blkRefId指向的块颜色
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
const val = color.getColorValue();
console.log(val);Parameters
| Name | Type | Description |
|---|---|---|
layerId? | McObjectId | 图层ID |
blkRefId? | McObjectId | 块记录ID |
Returns
string
颜色值字符串
getImp
▸ getImp(): any
获取内部实现对象
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
const imp = color.getImp();Returns
any
内部实现对象
getStyle
▸ getStyle(): string
获取 css 颜色的样式 如rgb(0, 0, 0)
Returns
string
setColorIndex
▸ setColorIndex(colorIndex): void
设置颜色索引,根据颜色索引值设置颜色类型。
Example
import { McCmColor, ColorIndexType } from "mxcad"
const color = new McCmColor();
color.setColorIndex(ColorIndexType.kBylayer);//设置颜色随层Parameters
| Name | Type | Description |
|---|---|---|
colorIndex | number | 颜色索引。 |
Returns
void
setRGB
▸ setRGB(red, green, blue): void
设置 RGB 值。
Example
import { McCmColor } from "mxcad"
const color = new McCmColor();
color.setRGB(255,0,0);//红色Parameters
| Name | Type | Description |
|---|---|---|
red | number | 红色值。 |
green | number | 绿色值。 |
blue | number | 蓝色值。 |
Returns
void