Skip to content
On this page

mxcad_2d API 文档 / 2d / McAppType

Class: McAppType

2d.McAppType

McAppType 类,提供了 MxCAD 的一些基本操作。

Example

ts
import { MxCpp } from "mxcad";

const McAppType = MxCpp.App;

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McAppType()

Properties

MxCADAssist

MxCADAssist: any

MxCAD辅助,内部使用

## Methods

### IniSet

▸ **IniSet**(`ini`): `boolean`

全局参数的初始设置

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ini` | `object` | 初始设置值 |

#### Returns

`boolean`

**`Example`**

```ts

addNetworkLoadingBigFont

addNetworkLoadingBigFont(fontfiles): void

配置需要通过网络加载的bigfont shx字体

Parameters

NameTypeDescription
fontfilesstring | string[]加载的字体文件

Returns

void

Example

ts
import { MxCpp } from 'mxcad'
import { MxFun } from "mxdraw";

// MxCAD创建成功
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
  MxCpp.App.addNetworkLoadingBigFont(["hztxt.shx", "gbcbig.shx"]);
}

addNetworkLoadingFont

addNetworkLoadingFont(fontfiles): void

配置需要通过网络加载的shx字体

Parameters

NameTypeDescription
fontfilesstring | string[]加载的字体文件

Returns

void

Example

ts
import { MxCpp } from 'mxcad';
import { MxFun } from "mxdraw";

// MxCAD创建成功
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
  MxCpp.App.addNetworkLoadingFont( ["txt.shx","simplex.shx","aaa.shx","ltypeshp.shx","complex.shx"]);
}

addNetworkLoadingTrueTypeFont

addNetworkLoadingTrueTypeFont(fontname, fontzhName, fontfile): void

配置需要通过网络加载的Truetype字体

Parameters

NameTypeDescription
fontnamestring[]字体名
fontzhNamestring[]字体中文名
fontfilestring[]加载字体文件

Returns

void

Example

ts
import { MxCpp } from 'mxcad'
import { MxFun } from "mxdraw";

// MxCAD创建成功
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
  MxCpp.App.addNetworkLoadingTrueTypeFont(["simsun","syadobe"],["思原宋体","思原黑体"],["stadobe.otf","syadobe.otf"]);
}

createCloneObject

createCloneObject(clonobjImp): null | McDbObject

创建克隆对象。

Parameters

NameTypeDescription
clonobjImpany被克隆的对象。

Returns

null | McDbObject

返回创建的 McDbObject 对象。

Example

ts
import { MxCADUiPrEntity, MxCpp } from "mxcad";
// 获取目标对象
let selEntity = new MxCADUiPrEntity();
let val = await selEntity.go();
if (!val.isValid()) return;

const obj = MxCpp.App.objectIdToObject(val.id);// 对象id转 McDbObject 对象
const obj_clone = MxCpp.App.createCloneObject(obj?.getImp());// 克隆目标对象

destroyObject

destroyObject(pObject): void

销毁对象。

Parameters

NameTypeDescription
pObjectMcRxObjectImp要销毁的对象。

Returns

void


getCurrentMxCAD

getCurrentMxCAD(): McObject

获取当前的 MxDraw 对象。

Returns

McObject

返回当前的 McObject 对象。

Example

ts
//添加图层
import { MxCpp } from 'mxcad'
// 获取当前cad对象
let mxcad = MxCpp.App.getCurrentMxCAD();
// 获取图层表
let layerTable = mxcad.getDatabase().getLayerTable();
if (!layerTable.has("xxx11")) {
  let newLayer = new McDbLayerTableRecord();// 构造新图层记录对象
  newLayer.name = "xxx11";// 设置新图层名为:"xxx11"
  layerTable.add(newLayer);// 图层表新增图层记录对象
}

if (layerTable.has("xxx11")) {
  console.log("add layer ok");
}

getImp

getImp(): any

获取 imp 对象。

Returns

any

返回 imp 对象。

Example

ts
import { MxCpp } from "mxcad";

const imp = MxCpp.App.getImp()

getLastCallResult

getLastCallResult(): number

获取最后一次调用的结果。

Returns

number

返回最后一次调用的结果

Example

ts
import { MxCpp } from "mxcad";

const result = MxCpp.App.getLastCallResult();
console.log("最后一次调用结果:", result);

getShxBigFonts

getShxBigFonts(): string[]

得到当前支持的所有bigfont shx字体.

Returns

string[]

字体数组

Example

ts
import { MxCpp } from "mxcad";

const bigFontArr = MxCpp.App.getShxBigFonts();
console.log(bigFontArr);

getShxFonts

getShxFonts(): string[]

得到当前支持的所有shx字体.

Returns

string[]

字体数组

Example

ts
import { MxCpp } from "mxcad";

const fontArr = MxCpp.App.getShxFonts();
console.log(fontArr);

getTrueTypeFonts

getTrueTypeFonts(): { file: string ; name: string ; zhname: string }[]

得到当前支持的所有TrueType字体.

Returns

{ file: string ; name: string ; zhname: string }[]

name 字体名| zhname 字体中文名 | file 字体文件

Example

ts
import { MxCpp } from "mxcad";

const trueTypeFontArr = MxCpp.App.getTrueTypeFonts();
console.log(trueTypeFontAr);

getVersionString

getVersionString(): string

得当前程序的版本信息

Returns

string

版本信息

Example

ts
import { MxCpp } from "mxcad";

const version = MxCpp.App.getVersionString();
console.log("版本信息", version);

init

init(imp): void

初始化 McAppType 对象。

Parameters

NameTypeDescription
impany传入的 imp 对象。

Returns

void

Example

ts
import { MxCpp } from "mxcad";

const imp = MxCpp.App.getImp();
MxCpp.App.init(imp);

loadFonts

loadFonts(vecShxFonst, vecBigShxFonst, vecTureTypeFonts, retCall): void

通知cad程序,将来要使用的字体需要加载,方便后面程序使用.

Parameters

NameTypeDescription
vecShxFonststring[]shx字体
vecBigShxFonststring[]bigfont shx字体
vecTureTypeFontsstring[]Truetype字体
retCall() => void回调函数

Returns

void

Example

ts
import { MxCpp } from 'mxcad';

  //修改文字样式
  function Mx_Test_TrueText(){
  let mxcad = MxCpp.getCurrentMxCAD();
  //清空当前显示内容
  mxcad.newFile();
  MxCpp.App.loadFonts([], [], ["syadobe","simsun"], () => {
    // 添加一个黑体文字样式
    mxcad.AddTureTypeTextStyle("ht_style","syadobe");
    // 添加一个宋体文字样式
    mxcad.AddTureTypeTextStyle("st_style","simsun");
    // 设置当前样式为黑体
    mxcad.drawTextStyle = "ht_style";
    mxcad.drawColor = new McCmColor(200, 255, 50);
    let idText = mxcad.drawText(0, 3500, "绘图控件TrueType文字测试", 100, 0, 0, 1);
    let ent = idText.getMcDbEntity();
    // 修改文字样式为宋体
    if(ent) ent.textStyle = "st_style";
    mxcad.zoomAll();
    mxcad.regen();
    mxcad.updateDisplay();
   });
 }

mcedRGB2Index

mcedRGB2Index(red, green, blue, bAutoNearest?): number

将 RGB 值转换为索引。

Parameters

NameTypeDefault valueDescription
rednumberundefined红色值。
greennumberundefined绿色值。
bluenumberundefined蓝色值。
bAutoNearestbooleantrue是否自动获取最近的颜色值。

Returns

number

返回转换后的索引值。

Example

ts
import { MxCpp } from 'mxcad'
const colorIndex = MxCpp.App.mcedRGB2Index(255, 0, 0, bAutoNearest)

objectIdIsKindOf

objectIdIsKindOf(lIdIndex, className): boolean

判断一个对象id是否指类类型名对象

Parameters

NameTypeDescription
lIdIndexnumber对象id索引
classNamestring对象名称

Returns

boolean

返回布尔值

Example

ts
import { MxCADUiPrEntity } from "mxcad";
// 选择目标对象
let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let val = await selEntity.go();
if (!val.isValid()) return;
// 判断目标对象是为多段线类
const isSuccess = MxCpp.objectIdIsKindOf(val.id, "McDbPolyline");
if(isSuccess){
  console.log("目标对象为多段线")
}else{
  console.log("目标对象不为多段线")  
}

objectIdToObject

objectIdToObject(lIdIndex): null | McDbObject

将对象 id 转换为 McDbObject 对象。

Parameters

NameTypeDescription
lIdIndexnumber对象的 id。

Returns

null | McDbObject

返回转换后的 McDbObject 对象,如果转换失败,则返回 null。

Example

ts
import { MxCADUiPrEntity, MxCpp } from "mxcad";
// 获取目标对象
let selEntity = new MxCADUiPrEntity();
let val = await selEntity.go();
if (!val.isValid()) return;
const obj = MxCpp.App.objectIdToObject(val.id);
console.log(obj)

setDefaultTrueTypeFontFile

setDefaultTrueTypeFontFile(sTrueTypeFontName): void

配置默认的TrueType字体

Parameters

NameTypeDescription
sTrueTypeFontNamestringTrueType字体名

Returns

void

Example

ts
import { MxCpp } from "mxcad";
//设置默认TrueType字体为Arial.ttf
MxCpp.setDefaultTrueTypeFontFile("Arial.ttf");

setDefaultViewBackgroundColor

setDefaultViewBackgroundColor(red, green, blue): void

设置默认的视区的背景色.

Parameters

NameTypeDescription
rednumber红色值。
greennumber绿色值。
bluenumber蓝色值。

Returns

void

Example

ts
import { MxCpp } from 'mxcad'
MxCpp.App.setDefaultViewBackgroundColor(0, 0, 0)

setFontFilePath

setFontFilePath(path): void

配置字体加载位置,默值是fonts

Parameters

NameTypeDescription
pathstring字体文件路径

Returns

void