Skip to content
On this page

mxcad_2d API 文档 / 2d / MxCADUtilityClass

Class: MxCADUtilityClass

2d.MxCADUtilityClass

MxCADUtilityClass 类提供了一系列与绘图相关的工具方法。

Example

ts
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

Constructors

constructor

new MxCADUtilityClass()

Methods

builderHatchFromPoint

builderHatchFromPoint(pt): null | McDbHatch

通过一个点坐标填充对应位置实体的填充

Parameters

NameTypeDescription
ptMcGePoint3d点对象

Returns

null | McDbHatch

返回一个填充对象

Example

ts
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);

calcBulge

calcBulge(pt1, pt2, pt3): Object

计算凸度

Parameters

NameTypeDescription
pt1McGePoint3d开始点
pt2McGePoint3d中点
pt3McGePoint3d结束点

Returns

Object

计算凸度结果

NameType
retboolean
valnumber

Example

ts
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)

eraseObject

eraseObject(lId, isErase?): boolean

eraseObject 方法用于删除指定的图形对象

Parameters

NameTypeDefault valueDescription
lIdnumberundefined需要删除的图形对象的 ID
isErasebooleantrue-

Returns

boolean

返回一个布尔值,表示是否删除成功

Example

ts
import { MxCADUtility, McGePoint3d } from "mxcad";

const lineId = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
const res = MxCADUtility.eraseObject(lineId)

findEntAtPoint

findEntAtPoint(dX, dY, dZ, dSearhRange?, filter?): McObjectId

findEntAtPoint 方法用于在指定坐标点附近查找图形对象

Parameters

NameTypeDefault valueDescription
dXnumberundefined坐标点的 X 坐标值
dYnumberundefined坐标点的 Y 坐标值
dZnumberundefined坐标点的 Z 坐标值
dSearhRangenumber-1查找范围,默认为 -1(表示查找整个绘图区域)
filternull | MxCADResbufnull过滤器,用于过滤查找到的图形对象,默认为 null(表示不进行过滤)

Returns

McObjectId

返回查找到的图形对象的 ID

Example

ts
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);

getCorner

getCorner(strPrompt?, pt1?, detailedResult?, drawSelectCroner?, isDisableAllTrace?, init?): Promise<null | { pt1: McGePoint3d ; pt2: McGePoint3d }>

获取角点(鼠标点击的两个点)

Parameters

NameTypeDefault valueDescription
strPrompt?stringundefined字符串提示
pt1?McGePoint3dundefined第一个点 (已知一个角点的情况)
detailedResult?(retcode: DetailedResult) => anyundefinedDetailedResult 交互结果讲台的回调
drawSelectCronerbooleanfalse绘制选择对象的选框(true有背景false无背景)
isDisableAllTracebooleanfalse是否禁用所有跟踪
init?(getPoint: MxCADUiPrPoint) => anyundefined-

Returns

Promise<null | { pt1: McGePoint3d ; pt2: McGePoint3d }>

返回一个 Promise,其中包含两个角点对象

Example

ts
import { MxCADUtility } from "mxcad";

const ret = await MxCADUtility.getCorner("测试");
if (!ret) return;
console.log(ret.pt1, ret.pt2)

getCurrentSelect

getCurrentSelect(filter?): McObjectId[]

得到当前选中的对象。

Parameters

NameTypeDefault valueDescription
filternull | MxCADResbufnull过滤对象

Returns

McObjectId[]

Example

ts
import { MxCADResbuf, MxCADUtility } from "mxcad";
  const filter = new MxCADResbuf();
  filter.AddMcDbEntityTypes('TEXT');
  const objIds = MxCADUtility.getCurrentSelect();
  console.log(objIds);

getCurrentSelectPoints

getCurrentSelectPoints(): Object

得到图上当前选择对象时,选择范围点.

Returns

Object

point1 角点1 | point2 角点2 | isvalid 是否有效

NameType
isvalidboolean
point1McGePoint3d
point2McGePoint3d

Example

ts
import { MxCADUtility } from "mxcad"
 let ids = MxCADUtility.getCurrentSelect()
 let pt1!: McGePoint3d, pt2!: McGePoint3d
 const { point1, point2 } = MxCADUtility.getCurrentSelectPoints()
 console.log(pt1, pt2)

getMcDbEntitysBoundingBox

getMcDbEntitysBoundingBox(aryId): undefined | { maxPt: McGePoint3d ; minPt: McGePoint3d }

获取多个实体形成的包围盒

Parameters

NameTypeDescription
aryIdMcObjectId[]实体对象ID数组

Returns

undefined | { maxPt: McGePoint3d ; minPt: McGePoint3d }

minPt 最小点 | maxPt 最大点

Example

ts
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)

highlightEntity

highlightEntity(lId, isHighlight?): any

highlightEntity 方法用于高亮指定的图形对象

Parameters

NameTypeDefault valueDescription
lIdnumberundefined需要高亮的图形对象的 ID
isHighlightbooleantrue是否需要高亮,默认为 true

Returns

any

Example

ts
import { MxCADUtility, McGePoint3d } from "mxcad";

const lineId = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
MxCADUtility.highlightEntity(lineId, true)

init

init(): void

初始化

Returns

void

Example

ts
import { MxCADUtility } from "mxcad";
 MxCADUtility.init()

selectEnt

selectEnt(strPrompt?, filter?, isSelectMxDraw?, init?, callbackGetPoint?): Promise<McObjectId[]>

selectEnt 方法用于在指定位置选择图形对象

Parameters

NameTypeDefault valueDescription
strPrompt?stringundefined选择时的提示信息,默认为 null(表示不显示提示信息)
filternull | MxCADResbufnull过滤器,用于过滤选择到的图形对象,默认为 null(表示不进行过滤)
isSelectMxDrawbooleantrue是否选择批注图形 默认true
init?(getPoint: MrxDbgUiPrPoint) => anyundefined选择图形前初始化函数( 会在实例化mxdraw取点类时触发,得到取点实例)
callbackGetPoint?(point: McGePoint3d) => voidundefined回调函数 获取选中图形时的坐标点

Returns

Promise<McObjectId[]>

返回一个 Promise,其中包含选择到的图形对象的 ID 数组

Example

ts
import { MxCADUtility, MxCADResbuf } from "mxcad";

// 定义过滤器
const filter = new MxCADResbuf()
filter.AddMcDbEntityTypes ("TEXT,LINE");

let retIds = await MxCADUtility.selectEnt("\n选择删除对象", filter);
console.log(retIds)

userSelect

userSelect(strPrompt?, filter?, init?): Promise<McObjectId[]>

用户选择

Parameters

NameTypeDefault valueDescription
strPrompt?stringundefined字符串提示
filternull | MxCADResbufnull过滤对象
init?(ss: MxCADSelectionSet, getPoint: MrxDbgUiPrPoint) => anyundefined-

Returns

Promise<McObjectId[]>

返回一个 Promise,其中包含得到选择的对象ID

Example

ts
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);