Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCADUtilityClass

Class: MxCADUtilityClass

2d.MxCADUtilityClass

The MxCADUtilityClass class provides a series of drawing related tool methods.

Example

ts
import { MxCADUtility, MxCADUiPrPoint } from "mxcad"
//Click to select
const getPoint = new MxCADUiPrPoint()
const point = await getPoint.go()
if(!point) return
let objId = MxCADUtility.findEntAtPoint(point.x, point.y,point.z,-1,filter)
//Select object and set highlight
MxCADUtility.highlightEntity(objId.id, true)
console.log(objId)

Table of contents

Constructors

Methods

Constructors

constructor

new MxCADUtilityClass()

Methods

builderHatchFromPoint

builderHatchFromPoint(pt): null | McDbHatch

Fill the corresponding position entity with a point coordinate

Parameters

NameTypeDescription
PtMcGePoint3d (2d. McGePoint3d. md)Point Object

Returns

null | McDbHatch

Return a filled object

Example

ts
import { MxCADUiPrPoint, MxCADUtility } from 'mxcad'
  const getPoint = new MxCADUiPrPoint();
GetPoint.setMessage ("\ nSpecify a point inside the filled area: ");
  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

Calculate convexity

Parameters

NameTypeDescription
Pt1McGePoint3d (2d. McGePoint3d. md)Start Point
Pt2[McGePoint3d] (2d. McGePoint3d. md)Midpoint
Pt3McGePoint3d (2d. McGePoint3d. md)End Point

Returns

Object

Calculate the convexity result

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

The eraseObject method is used to delete a specified graphic object

Parameters

NameTypeDefault valueDescription
IdnumberundefinedID of the graphic object that needs to be deleted
isErasebooleantrue-

Returns

boolean

Return a Boolean value indicating whether the deletion was successful

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

The findEntAtPoint method is used to search for graphic objects near a specified coordinate point

Parameters

NameTypeDefault valueDescription
DXnumberundefinedX coordinate value of the coordinate point
DYnumberundefinedY coordinate value of the coordinate point
DZnumberundefinedZ coordinate value of the coordinate point
DSearhRangenumber-1Search range, default is -1 (indicating search for the entire drawing area)
filternull \[MxCADResbuf] (2d. MxCADResbuf. md)null

Returns

McObjectId

Return the ID of the found graphic object

Example

ts
import { MxCADUiPrPoint, MxCADUtility, MxCpp } from "mxcad"
  const mxcad = MxCpp.getCurrentCAD();
  const getPoint = new MxCADUiPrPoint();
GetPoint.setMessage ('Please select object ');
  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 }>

Get corner points (two points clicked by the mouse)

Parameters

NameTypeDefault valueDescription
strPrompt?` StringundefinedString prompt
pt1?[McGePoint3d] (2d. McGePoint3d. md)undefinedFirst point (when a corner point is known)
detailedResult?(retcode: DetailedResult)=>anyundefinedDetailedResult Interaction Result Platform callback
DrawSelectCronerbooleanfalseDraw a checkbox for the selected object (true with background, false without background)
IsDisabAllTracebooleanfalseDo you want to disable all traces
init?(getPoint: MxCADUiPrPoint) => anyundefined-

Returns

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

Return a Promise containing two corner objects

Example

ts
import { MxCADUtility } from "mxcad";

Const ret=await MxCADUtility. getCorner ("test");
if (!ret) return;
console.log(ret.pt1, ret.pt2)

getCurrentSelect

getCurrentSelect(filter?, returnMxCADObject?, returnMxDrawObject?): McObjectId[]

Get the currently selected object.

Parameters

NameTypeDefault valueDescription
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null
returnMxCADObjectbooleantrue-
returnMxDrawObjectbooleantrue-

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

When obtaining the current selected object on the graph, select the range point

Returns

Object

Point1 Corner 1 | Point2 Corner 2 | Is invalid

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 }

Obtain a bounding box formed by multiple entities

Parameters

NameTypeDescription
AryId[McObject Id] (2d. McObject Id. md) []Entity Object ID Array

Returns

undefined | { maxPt: McGePoint3d ; minPt: McGePoint3d }

MinPt minimum point | maxPt maximum point

Example

ts
import { MxCADUtility } from "mxcad";

Let aryId=await MxCADUtility. userSelect ("Select Target Object");
  let ext = MxCADUtility.getMcDbEntitysBoundingBox(aryId);
  if (!ext) return;
Console.log ("minimum point", ext.minPt)
Console.log ("maximum point", ext.maxPt)

getTextBox

getTextBox(str, dTextHeight, dWidthFactor, idTextStyleRecord): Object

Outsourcing box for calculating text

Parameters

NameType
strstring
dTextHeightnumber
dWidthFactornumber
idTextStyleRecordMcObjectId

Returns

Object

NameType
maxPtMcGePoint3d
minPtMcGePoint3d
retboolean

highlightEntity

highlightEntity(lId, isHighlight?): any

The highlightEntity method is used to highlight a specified graphic object

Parameters

NameTypeDefault valueDescription
IdnumberundefinedID of the graphic object that needs to be highlighted
IsHighlightbooleantrueWhether to highlight, default to 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

initialization

Returns

void

Example

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

pointInPolygon

pointInPolygon(aryPoint, x, y): boolean

Determine whether a point is within a closed area

Parameters

NameType
aryPointMcGePoint3dArray
xnumber
yNumber

Returns

boolean

Example

ts

selectEnt

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

The selectEnt method is used to select graphic objects at a specified location

Parameters

NameTypeDefault valueDescription
strPrompt?` StringundefinedThe prompt message when selecting, default to null (indicating no prompt message displayed)
filternull \[MxCADResbuf] (2d. MxCADResbuf. md)null
IsSelectMxDrawbooleantrueWhether to select annotation graphics default to true
init?(getPoint: MrxDBgUiPrPoint)=>anyundefinedInitialize the function before selecting the shape (will be instantiated with the [mxdraw point class])( https://mxcadx.gitee.io/mxdraw_api_docs/classes/MrxDbgUiPrPoint.html )Triggered at the moment, obtain a point instance)
callbackGetPoint?(point: [McGePoint3d] (2d. McGePoint3d. md))=>voidundefinedThe callback function retrieves the coordinate points of the selected shape

Returns

Promise<McObjectId[]>

Return a Promise containing an array of IDs for the selected graphic object

Example

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

//Define filters
const filter = new MxCADResbuf()
filter.AddMcDbEntityTypes ("TEXT,LINE");

Let retIds=await MxCADUtility. setEnt ("\ nSelect to delete object", filter);
console.log(retIds)

userSelect

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

User selection

Parameters

NameTypeDefault valueDescription
strPrompt?` StringundefinedString prompt
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null
init?(ss: MxCADSelectionSet, getPoint: MrxDbgUiPrPoint) => anyundefined-

Returns

Promise<McObjectId[]>

Return a Promise containing the selected object ID

Example

ts
import { MxCADResbuf, MxCADUtility } from 'mxcad';
   let filter = new MxCADResbuf();
   filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
Let aryId=await MxCADUtility. userSelect ("Select target curve", filter);
   console.log(aryId);