Skip to content

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

Module: 2d ​

Contains 2D related exports for displaying CAD drawings, and all exported content can be imported directly using the MXCAD package

Example

js
import { createMxCad, McCmColor, McDbEntity } from "mxcad"

Table of contents ​

Namespaces ​

Enumerations ​

Classes ​

Interfaces ​

Type Aliases ​

Variables ​

Functions ​

Type Aliases ​

CreateColorArgs ​

Ƭ CreateColorArgs: THREEColorArgs | [Partial<McCmColorJSON> | McCmColor]

Used to specify different types of parameter forms that can be accepted when creating colors


ITableStyleInfo ​

Ƭ ITableStyleInfo: Partial<Omit<ITableStyle, "name">>


McCmColorJSON ​

Ƭ McCmColorJSON: ExcludePropertiesContainingThisType<McCmColor, Function>

The JSON version of McCMColor


SegmentPointPair ​

Ƭ SegmentPointPair: [McGePoint3d, McGePoint3d]

Point to point types of data associated with line segments


THREEColorArgs ​

Ƭ THREEColorArgs: [string | number | THREE.Color] | ConstructorArguments<typeof THREE.Color> | []

The tuple composed of the parameter types of the THREE. Color constructor: string, number THREE.Color

Variables ​

MxCADUtility ​

• MxCADUtility: MxCADUtilityClass

Provides a series of drawing related tools and methods


MxCoordConvert ​

• MxCoordConvert: MxCoordConvertType

Provide coordinate conversion methods, which are only for calling our MxCAD compatible code and will not be exported to users


MxCpp ​

• MxCpp: MxCppType

Functions ​

MxCheckTheBrowser ​

▸ MxCheckTheBrowser(): Object

Check browser type and version

Returns ​

Object

OK Boolean value, indicating whether the browser meets the requirements | error. If the browser does not meet the requirements, it contains an error message; Otherwise, it is an empty string | var contains an object with browser information

NameType
errorstring
okboolean
varany

Example

ts
 import { MxCheckTheBrowser } from 'mxcad'; 

 const browserCheckResult = MxCheckTheBrowser();
 if (browserCheckResult.ok) {
Console.log ('The browser meets the requirements and can load MxCAD assembly.');
//Call the loadMxCADassembly function here to load MxCAD assembly
 } else {
Console.error ('Browser does not meet requirements: ', browserCheckResult.error);
//Handling situations where the browser does not meet the requirements here may provide user-friendly prompts or take other measures
 }

MxRegistCommand ​

▸ MxRegistCommand(): void

Returns ​

void


Mx_About ​

▸ Mx_About(): void

Returns ​

void


Mx_Erase ​

▸ Mx_Erase(): Promise<void>

delete object

Returns ​

Promise<void>


createMcCmColor ​

▸ createMcCmColor(...ages): McCmColor

Create color objects

Parameters ​

NameTypeDescription
`... Ages[CreateColorArgs] (2d. md # creatcolors)Color parameter type

Returns ​

McCmColor

Color Object


createMxCad ​

▸ createMxCad(config?, mxcadobj?): Promise<McObject>

Create MxCad instance

Parameters ​

NameTypeDescription
config?[MxCadConfig] (../interfaces/2d. MxCadConfig. md)Parameter Configuration
mxcadobj?[McObject] (../classes/2d. McObject. md)Object

Returns ​

Promise<McObject>

Example

//Create an instance to display the drawings using the Vite packaging tool

ts
import { createMxCad } from "mxcad";

createMxCad({
  canvas: "#mxcad",
  locateFile: (fileName) => new URL(`/node_modules/mxcad/dist/wasm/2d/${fileName}`, import.meta.url).href,
//Please note that when providing the file to be opened/ Assets/test.mxweb is the file address in the relative path,
//In Vite, the correct network address of the file can be obtained through this method
  fileUrl: new URL("../assets/test.mxweb", import.meta.url).href,
//Provide the directory path for loading fonts
  fontspath: new URL("node_modules/mxcad/dist/fonts", import.meta.url).href,
})

drawArc ​

▸ drawArc(): Promise<void>

Draw an arc

Returns ​

Promise<void>


drawCircle ​

▸ drawCircle(): Promise<undefined | McObjectId>

circle

Returns ​

Promise<undefined | McObjectId>


drawEllipticalArc ​

▸ drawEllipticalArc(): Promise<undefined | McObjectId>

Draw an ellipse or elliptical arc

Returns ​

Promise<undefined | McObjectId>


drawLine ​

▸ drawLine(): Promise<void>

Draw a straight line

Returns ​

Promise<void>


drawMText ​

▸ drawMText(): Promise<undefined | McObjectId>

Draw multiple lines of text

Returns ​

Promise<undefined | McObjectId>


drawPolyLine ​

▸ drawPolyLine(): Promise<undefined | McObjectId>

Draw polylines

Returns ​

Promise<undefined | McObjectId>


drawPolygon ​

▸ drawPolygon(): Promise<void>

Draw regular polygons

Returns ​

Promise<void>


drawRectang ​

▸ drawRectang(): Promise<void>

draw rectangle

Returns ​

Promise<void>


drawText ​

▸ drawText(): Promise<undefined | McObjectId>

Draw Text

Returns ​

Promise<undefined | McObjectId>


getColorUtils ​

▸ getColorUtils(...ages): Color

Get Color Tool

Parameters ​

NameTypeDescription
`... Ages[THREEColorArgs] (2d. md # threecolorArgs)Color Parameters

Returns ​

Color

THREE.Color


getFilterImp ​

▸ getFilterImp(filter?): any

Retrieve a CAD (Computer Aided Design) filter

Parameters ​

NameTypeDefault valueDescription
Filternull[MxCADResbuff] (../classes/2d. MxCADResbuff. md)null

Returns ​

any

CAD filter imp


loadMxCADassembly ​

▸ loadMxCADassembly(call?, locateFile?, wasmBinary?, fontspath?, networkFonts?, mxcad?, wasmx64?): Promise<MxCppType>

Asynchronous loading of MxCAD assembly and execution of callback function after loading completion

Parameters ​

NameTypeDefault valueDescription
call? (MxCpp: [MxCppType] (../classes/2d. MxCppType. md))=>voidundefinedThe callback function is executed after loading is complete
The locateFileanyundefinedfunction is used to determine the location of the wasm file, and a default value is provided here
wasmBinary? [ArrayBuffer]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer )undefinedWasm binary data
fontspath? stringundefinedPath to font file
networkFonts? string []undefinedArray of network fonts
mxcad?anyundefined-
wasmx64?anyundefined-

Returns ​

Promise<MxCppType>

Return a Promise object containing an instance of type MxCppType

Example

ts
   import { loadMxCADassembly } from "mxcad"

//Call the loadMxCADassembly function and process the returned Promise
   loadMxCADassembly(
     (MxCpp) => {
Console.log ('MxCAD assembly loaded ');
//Here, you can operate the MxCAD assembly
     },
//Optional parameters, you can provide positioning functions and other parameters as needed
   ).then((MxCpp) => {
Console.log ('MxCAD assembly loading completed ');
//Here, you can continue processing the MxCAD assembly after loading is complete
   }).catch((error) => {
Console.error ('Error loading MxCAD assembly:', error);
   });

setMcCmColor ​

▸ setMcCmColor(mcCmColor, ...ages): void

Set color

Parameters ​

NameTypeDescription
McCmColor[McCMColor] (../classes/2d. McCMColor. md)Color Object
`... Ages[CreateColorArgs] (2d. md # creatcolors)Color parameter type

Returns ​

void