[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
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
- builderHatchFromPoint
- calcBulge
- eraseObject
- findEntAtPoint
- getCorner
- getCurrentSelect
- getCurrentSelectPoints
- getMcDbEntitysBoundingBox
- getTextBox
- getTextEntityBox
- highlightEntity
- init
- pointInPolygon
- selectEnt
- userSelect
Constructors
constructor
• new MxCADUtilityClass()
Methods
builderHatchFromPoint
▸ builderHatchFromPoint(pt): null | McDbHatch
Fill the corresponding position entity with a point coordinate
Parameters
| Name | Type | Description |
|---|---|---|
| Pt | McGePoint3d (2d. McGePoint3d. md) | Point Object |
Returns
null | McDbHatch
Return a filled object
Example
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
| Name | Type | Description |
|---|---|---|
| Pt1 | McGePoint3d (2d. McGePoint3d. md) | Start Point |
| Pt2 | [McGePoint3d] (2d. McGePoint3d. md) | Midpoint |
| Pt3 | McGePoint3d (2d. McGePoint3d. md) | End Point |
Returns
Object
Calculate the convexity result
| Name | Type |
|---|---|
ret | boolean |
val | number |
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)eraseObject
▸ eraseObject(lId, isErase?): boolean
The eraseObject method is used to delete a specified graphic object
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Id | number | undefined | ID of the graphic object that needs to be deleted |
isErase | boolean | true | - |
Returns
boolean
Return a Boolean value indicating whether the deletion was successful
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)findEntAtPoint
▸ findEntAtPoint(dX, dY, dZ, dSearhRange?, filter?): McObjectId
The findEntAtPoint method is used to search for graphic objects near a specified coordinate point
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| DX | number | undefined | X coordinate value of the coordinate point |
| DY | number | undefined | Y coordinate value of the coordinate point |
| DZ | number | undefined | Z coordinate value of the coordinate point |
| DSearhRange | number | -1 | Search range, default is -1 (indicating search for the entire drawing area) |
filter | null \ | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
Returns
Return the ID of the found graphic object
Example
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
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | undefined | String prompt |
pt1? | [McGePoint3d] (2d. McGePoint3d. md) | undefined | First point (when a corner point is known) |
detailedResult? | (retcode: DetailedResult)=>any | undefined | DetailedResult Interaction Result Platform callback |
| DrawSelectCroner | boolean | false | Draw a checkbox for the selected object (true with background, false without background) |
| IsDisabAllTrace | boolean | false | Do you want to disable all traces |
init? | (getPoint: MxCADUiPrPoint) => any | undefined | - |
Returns
Promise<null | { pt1: McGePoint3d ; pt2: McGePoint3d }>
Return a Promise containing two corner objects
Example
import { MxCADUtility } from "mxcad";
Const ret=await MxCADUtility. getCorner ("test");
if (!ret) return;
console.log(ret.pt1, ret.pt2)getCurrentSelect
▸ getCurrentSelect(filter?, returnMxCADObject?, returnMxDrawObject?, whenEmptyReturnPrvSelect?): McObjectId[]
Get the currently selected object.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
returnMxCADObject | boolean | true | - |
returnMxDrawObject | boolean | true | - |
whenEmptyReturnPrvSelect | boolean | true | - |
Returns
Example
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
| Name | Type |
|---|---|
isvalid | boolean |
point1 | McGePoint3d |
point2 | McGePoint3d |
Example
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
| Name | Type | Description |
|---|---|---|
| AryId | [McObject Id] (2d. McObject Id. md) [] | Entity Object ID Array |
Returns
undefined | { maxPt: McGePoint3d ; minPt: McGePoint3d }
MinPt minimum point | maxPt maximum point
Example
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
| Name | Type |
|---|---|
str | string |
dTextHeight | number |
dWidthFactor | number |
idTextStyleRecord | McObjectId |
Returns
Object
| Name | Type |
|---|---|
maxPt | McGePoint3d |
minPt | McGePoint3d |
ret | boolean |
getTextEntityBox
▸ getTextEntityBox(text, isTrimLastSpace?): Object
Calculate the bounding box of text objects
Parameters
| Name | Type | Default value |
|---|---|---|
text | McDbEntity | undefined |
isTrimLastSpace | boolean | true |
Returns
Object
| Name | Type |
|---|---|
maxPt | McGePoint3d |
minPt | McGePoint3d |
ret | boolean |
highlightEntity
▸ highlightEntity(lId, isHighlight?): any
The highlightEntity method is used to highlight a specified graphic object
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Id | number | undefined | ID of the graphic object that needs to be highlighted |
| IsHighlight | boolean | true | Whether to highlight, default to true |
Returns
any
Example
import { MxCADUtility, McGePoint3d } from "mxcad";
const lineId = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
MxCADUtility.highlightEntity(lineId.id, true)init
▸ init(): void
initialization
Returns
void
Example
import { MxCADUtility } from "mxcad";
MxCADUtility.init()pointInPolygon
▸ pointInPolygon(aryPoint, x, y): boolean
Determine whether a point is within a closed area
Parameters
| Name | Type |
|---|---|
aryPoint | McGePoint3dArray |
x | number |
y | Number |
Returns
boolean
Example
selectEnt
▸ selectEnt(strPrompt?, filter?, isSelectMxDraw?, init?, callbackGetPoint?): Promise<McObjectId[]>
The selectEnt method is used to select graphic objects at a specified location
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | undefined | Prompt message when selecting, default to null (indicating no prompt message displayed) |
filter | null \ | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
| IsSelectMxDraw | boolean | true | Whether to select annotation graphics default to true |
init? | (getPoint: MrxDBgUiPrPoint)=>any | undefined | Initialize the function before selecting the shape (will be instantiated in 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))=>void | undefined | The callback function retrieves the coordinate points of the selected shape |
Returns
Return a Promise containing an array of IDs for the selected graphic object
Example
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
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | undefined | String prompt |
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
init? | (ss: MxCADSelectionSet, getPoint: MrxDbgUiPrPoint) => any | undefined | - |
Returns
Return a Promise containing the selected object ID
Example
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);