Skip to content

mxcad_2d API 文档 / 2d / MxCppType

Class: MxCppType

2d.MxCppType

MxCppType 是 MxCAD 全局 API 的入口包装类。

Description

该类统一封装了 MxCAD 全局功能,包括底层程序集访问、当前 CAD 对象获取、属性窗口接口、AI 接口、几何对象创建以及字符编码转换。 它让插件开发者可以通过一个统一对象访问 MxCAD 的顶层服务。 使用方法总结:

  1. 通过 MxCpp 访问 MxCppType 实例;
  2. 使用 AppPropertiesWindowAi 等成员获取对应功能入口;
  3. 调用 newMcGePoint3ddecodeFromGb2312 等辅助方法完成常见操作。

Example

ts
import { MxCpp } from "mxcad";

const mxcad = MxCpp.getCurrentMxCAD();
const point = MxCpp.newMcGePoint3d({ x: 100, y: 200, z: 0 });
const decoded = MxCpp.decodeFromGb2312("%c4%e3%ba%c3");
console.log(mxcad, point, decoded);

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new MxCppType()

Properties

Ai

Ai: MxAI

Mx AI实例


App

App: McAppType

McAppType 实例


PropertiesWindow

PropertiesWindow: MxPropertiesWindowCustom

PropertiesWindow 属必窗口功能调用实例

Example

ts
import { MxCpp } from "mxcad";
  
// 属性界面上,对象属性被修改事件。
MxCpp.PropertiesWindow.onEvent_setProperties((id: McObjectId, prop: any) => {
  let ent = id.getMcDbEntity();
  if (!ent) return;
  if (prop.sVarName == "DN") {
        ent.setxDataDouble("DN", prop.val);
  }
 else if (prop.sVarName == "LEN") {
     ent.setxDataDouble("LEN", prop.val);
  }
});

mxcadassemblyimp

Optional mxcadassemblyimp: any

MxCpp 程序集

Example

ts
//获取与修剪相关的信息
import { MxCpp } from "mxcad";

let mxcadTrimAssert = new MxCpp.mxcadassemblyimp.MxDrawTrimAssist()

Accessors

currentDatabase

get currentDatabase(): McDbDatabase

返回当前活动的CAD对象的数据库对象.

Returns

McDbDatabase


mxcad

get mxcad(): McObject

返回当前活动的CAD对象

Returns

McObject

Methods

decodeFromGb2312

decodeFromGb2312(strHex): string

把hex格式的Gb2312编码的转成utf8

Parameters

NameTypeDescription
strHexstringGb2312编码

Returns

string

Example

ts
import { MxCpp } from "mxcad";

const gb2312Hex = "%c4%e3%ba%c3";
const decodedString = MxCpp.decodeFromGb2312(gb2312Hex);
console.log("Decoded string from GB2312 hex:", decodedString);

encodeToGb2312

encodeToGb2312(str): string

把utf8转成hex格式的Gb2312编码

Parameters

NameTypeDescription
strstring字符串

Returns

string

Example

ts
import { MxCpp } from "mxcad";
const stringToEncode = "你好";
const encodedHex = MxCpp.encodeToGb2312(stringToEncode);
console.log("Encoded string to GB2312 hex:", encodedHex);

getCallResult

getCallResult(): number

获取上一次调用的结果

Returns

number

调用结果


getCurrentDatabase

getCurrentDatabase(): McDbDatabase

返回当前活动的CAD对象的数据库对象.

Returns

McDbDatabase


getCurrentMxCAD

getCurrentMxCAD(): McObject

返回当前活动的CAD对象

Returns

McObject


getIdFromCpp

getIdFromCpp(id): any

得到cpp转过的id

Parameters

NameType
idstring | number

Returns

any


newMcGePoint3d

newMcGePoint3d(pt?): McGePoint3d

创建新的 McGePoint3d 实例

Parameters

NameTypeDescription
pt?any点坐标

Returns

McGePoint3d

McGePoint3d 实例


newMcGeVector3d

newMcGeVector3d(pt?): McGeVector3d

创建新的 McGeVector3d 实例

Parameters

NameTypeDescription
pt?any点坐标

Returns

McGeVector3d

McGeVector3d 实例