mxcad_2d API 文档 / 2d / MxCADUtilityClass
Class: MxCADUtilityClass
2d.MxCADUtilityClass
MxCADUtilityClass 类提供了一系列与绘图相关的工具方法。
Example
import { MxCADUtility, MxCADUiPrPoint } from "mxcad"
//点选
const getPoint = new MxCADUiPrPoint()
const point = await getPoint.go()
if(!point) return
let objId = MxCADUtility.findEntAtPoint(point.x, point.y,point.z,-1,filter)
// 选中对象设置高亮
MxCADUtility.highlightEntity(objId.id, true)
console.log(objId)
Table of contents
Constructors
Methods
- builderHatchFromPoint
- calcBulge
- eraseObject
- findEntAtPoint
- getCorner
- getCurrentSelect
- getCurrentSelectPoints
- getMcDbEntitysBoundingBox
- highlightEntity
- init
- selectEnt
- userSelect
Constructors
constructor
• new MxCADUtilityClass()
Methods
builderHatchFromPoint
▸ builderHatchFromPoint(pt
): null
| McDbHatch
通过一个点坐标填充对应位置实体的填充
Example
import { MxCADUiPrPoint, MxCADUtility } from 'mxcad'
const getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\n指定填充区域内部一点:");
getPoint.disableAllTrace(true);
getPoint.setDisableOsnap(true);
let pt = (await getPoint.go()) as McGePoint3d;
if (!pt) return;
let hatch = MxCADUtility.builderHatchFromPoint(pt);
Parameters
Name | Type | Description |
---|---|---|
pt | McGePoint3d | 点对象 |
Returns
null
| McDbHatch
返回一个填充对象
calcBulge
▸ calcBulge(pt1
, pt2
, pt3
): Object
计算凸度
Example
import { McGePoint3d, MxCADUtility } from "mxcad"
const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,10,0);
const pt3 = new McGePoint3d(40,0,0);
const Bulge = MxCADUtility.calcBulge(pt1, pt2, pt3);
console.log(Bulge)
Parameters
Name | Type | Description |
---|---|---|
pt1 | McGePoint3d | 开始点 |
pt2 | McGePoint3d | 中点 |
pt3 | McGePoint3d | 结束点 |
Returns
Object
计算凸度结果
Name | Type |
---|---|
ret | boolean |
val | number |
eraseObject
▸ eraseObject(lId
, isErase?
): boolean
eraseObject 方法用于删除指定的图形对象
Example
import { MxCADUtility, McGePoint3d } from "mxcad";
const lineId = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
const res = MxCADUtility.eraseObject(lineId)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
lId | number | undefined | 需要删除的图形对象的 ID |
isErase | boolean | true | - |
Returns
boolean
返回一个布尔值,表示是否删除成功
findEntAtPoint
▸ findEntAtPoint(dX
, dY
, dZ
, dSearhRange?
, filter?
): McObjectId
findEntAtPoint 方法用于在指定坐标点附近查找图形对象
Example
import { MxCADUiPrPoint, MxCADUtility, MxCpp } from "mxcad"
const mxcad = MxCpp.getCurrentCAD();
const getPoint = new MxCADUiPrPoint();
getPoint.setMessage('请选择对象\n');
const point = await getPoint.go();
if (!point) break;
let objId = MxCADUtility.findEntAtPoint(point.x, point.y, point.z, -1, filter);
mxcad.addCurrentSelect(objId);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dX | number | undefined | 坐标点的 X 坐标值 |
dY | number | undefined | 坐标点的 Y 坐标值 |
dZ | number | undefined | 坐标点的 Z 坐标值 |
dSearhRange | number | -1 | 查找范围,默认为 -1(表示查找整个绘图区域) |
filter | null | MxCADResbuf | null | 过滤器,用于过滤查找到的图形对象,默认为 null(表示不进行过滤) |
Returns
返回查找到的图形对象的 ID
getCorner
▸ getCorner(strPrompt?
, pt1?
, detailedResult?
, drawSelectCroner?
, isDisableAllTrace?
, init?
): Promise
<null
| { pt1
: McGePoint3d
; pt2
: McGePoint3d
}>
获取角点(鼠标点击的两个点)
Example
import { MxCADUtility } from "mxcad";
const ret = await MxCADUtility.getCorner("测试");
if (!ret) return;
console.log(ret.pt1, ret.pt2)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
strPrompt? | string | undefined | 字符串提示 |
pt1? | McGePoint3d | undefined | 第一个点 (已知一个角点的情况) |
detailedResult? | (retcode : DetailedResult ) => any | undefined | DetailedResult 交互结果讲台的回调 |
drawSelectCroner | boolean | false | 绘制选择对象的选框(true有背景false无背景) |
isDisableAllTrace | boolean | false | 是否禁用所有跟踪 |
init? | (getPoint : MxCADUiPrPoint ) => any | undefined | - |
Returns
Promise
<null
| { pt1
: McGePoint3d
; pt2
: McGePoint3d
}>
返回一个 Promise,其中包含两个角点对象
getCurrentSelect
▸ getCurrentSelect(filter?
): McObjectId
[]
得到当前选中的对象。
Example
import { MxCADResbuf, MxCADUtility } from "mxcad";
const filter = new MxCADResbuf();
filter.AddMcDbEntityTypes('TEXT');
const objIds = MxCADUtility.getCurrentSelect();
console.log(objIds);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
filter | null | MxCADResbuf | null | 过滤对象 |
Returns
getCurrentSelectPoints
▸ getCurrentSelectPoints(): Object
得到图上当前选择对象时,选择范围点.
Example
import { MxCADUtility } from "mxcad"
let ids = MxCADUtility.getCurrentSelect()
let pt1!: McGePoint3d, pt2!: McGePoint3d
const { point1, point2 } = MxCADUtility.getCurrentSelectPoints()
console.log(pt1, pt2)
Returns
Object
point1 角点1 | point2 角点2 | isvalid 是否有效
Name | Type |
---|---|
isvalid | boolean |
point1 | McGePoint3d |
point2 | McGePoint3d |
getMcDbEntitysBoundingBox
▸ getMcDbEntitysBoundingBox(aryId
): undefined
| { maxPt
: McGePoint3d
; minPt
: McGePoint3d
}
获取多个实体形成的包围盒
Example
import { MxCADUtility } from "mxcad";
let aryId = await MxCADUtility.userSelect("选择目标对象");
let ext = MxCADUtility.getMcDbEntitysBoundingBox(aryId);
if (!ext) return;
console.log("最小点",ext.minPt)
console.log("最大点", ext.maxPt)
Parameters
Name | Type | Description |
---|---|---|
aryId | McObjectId [] | 实体对象ID数组 |
Returns
undefined
| { maxPt
: McGePoint3d
; minPt
: McGePoint3d
}
minPt 最小点 | maxPt 最大点
highlightEntity
▸ highlightEntity(lId
, isHighlight?
): any
highlightEntity 方法用于高亮指定的图形对象
Example
import { MxCADUtility, McGePoint3d } from "mxcad";
const lineId = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
MxCADUtility.highlightEntity(lineId, true)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
lId | number | undefined | 需要高亮的图形对象的 ID |
isHighlight | boolean | true | 是否需要高亮,默认为 true |
Returns
any
init
▸ init(): void
初始化
Example
import { MxCADUtility } from "mxcad";
MxCADUtility.init()
Returns
void
selectEnt
▸ selectEnt(strPrompt?
, filter?
, isSelectMxDraw?
, init?
, callbackGetPoint?
): Promise
<McObjectId
[]>
selectEnt 方法用于在指定位置选择图形对象
Example
import { MxCADUtility, MxCADResbuf } from "mxcad";
// 定义过滤器
const filter = new MxCADResbuf()
filter.AddMcDbEntityTypes ("TEXT,LINE");
let retIds = await MxCADUtility.selectEnt("\n选择删除对象", filter);
console.log(retIds)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
strPrompt? | string | undefined | 选择时的提示信息,默认为 null(表示不显示提示信息) |
filter | null | MxCADResbuf | null | 过滤器,用于过滤选择到的图形对象,默认为 null(表示不进行过滤) |
isSelectMxDraw | boolean | true | 是否选择批注图形 默认true |
init? | (getPoint : MrxDbgUiPrPoint ) => any | undefined | 选择图形前初始化函数( 会在实例化mxdraw取点类时触发,得到取点实例) |
callbackGetPoint? | (point : McGePoint3d ) => void | undefined | 回调函数 获取选中图形时的坐标点 |
Returns
返回一个 Promise,其中包含选择到的图形对象的 ID 数组
userSelect
▸ userSelect(strPrompt?
, filter?
, init?
): Promise
<McObjectId
[]>
用户选择
Example
import { MxCADResbuf, MxCADUtility } from 'mxcad';
let filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
let aryId = await MxCADUtility.userSelect("选择目标曲线", filter);
console.log(aryId);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
strPrompt? | string | undefined | 字符串提示 |
filter | null | MxCADResbuf | null | 过滤对象 |
init? | (ss : MxCADSelectionSet , getPoint : MrxDbgUiPrPoint ) => any | undefined | - |
Returns
返回一个 Promise,其中包含得到选择的对象ID