[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
import { createMxCad, McCmColor, McDbEntity } from "mxcad"
Table of contents
Namespaces
Enumerations
- ColorIndexType
- ColorMethod
- DxfCode
- FetchAttributes
- McObjectIdType
- MxCADCloneType
- MxCADSelectionSetStatus
- MxPropertiesWindowCustomValueType
Classes
- IMcDbDwgFiler
- McAppType
- McCmColor
- McDb2LineAngularDimension
- McDbAlignedDimension
- McDbArc
- McDbAttribute
- McDbAttributeDefinition
- McDbBackgroundEntity
- McDbBlockReference
- McDbBlockTable
- McDbBlockTableRecord
- McDbCircle
- McDbCurve
- McDbCustomEntity
- McDbDatabase
- McDbDictionary
- McDbDimStyleTable
- McDbDimStyleTableRecord
- McDbDimension
- McDbEllipse
- McDbEntity
- McDbGroup
- McDbHatch
- McDbLayerTable
- McDbLayerTableRecord
- McDbLine
- McDbLinetypeTable
- McDbLinetypeTableRecord
- McDbMText
- McDbObject
- McDbObjectArray
- McDbPoint
- McDbPolyline
- McDbProxyEntity
- McDbRasterImage
- McDbRasterImageDef
- McDbRotatedDimension
- McDbSpatialFilter
- McDbSpline
- McDbText
- McDbTextStyleTable
- McDbTextStyleTableRecord
- McDbWipeout
- McDbXrecord
- McGeBound
- McGeDoubleArray
- McGeLongArray
- McGeMatrix3d
- McGePoint3d
- McGePoint3dArray
- McGeStringArray
- McGeVector3d
- McObject
- McObjectId
- McRxObject
- MxCADPluginBase
- MxCADPluginMapDefaultData
- MxCADPluginSampleCode
- MxCADResbuf
- MxCADSelectionSet
- MxCADTempForbiddenIntelliSelect
- MxCADUiPrAngle
- MxCADUiPrBase
- MxCADUiPrDist
- MxCADUiPrEntity
- MxCADUiPrInt
- MxCADUiPrKeyWord
- MxCADUiPrPoint
- MxCADUiPrString
- MxCADUtilityClass
- MxCADWorldDraw
- MxCompare
- MxCoordConvertType
- MxCppType
- MxModifyColor
- MxPropertiesWindowCustom
- MxPropertiesWindowCustomValue
Interfaces
Type Aliases
Variables
Functions
- MxCheckTheBrowser
- Mx_About
- Mx_Erase
- createMcCmColor
- createMxCad
- drawArc
- drawCircle
- drawEllipticalArc
- drawLine
- drawMText
- drawPolyLine
- drawPolygon
- drawRectang
- drawText
- getColorUtils
- getFilterImp
- loadMxCADassembly
- setMcCmColor
Type Aliases
CreateColorArgs
Ƭ CreateColorArgs: THREEColorArgs
| [Partial
<McCmColorJSON
> | McCmColor
]
Used to specify different types of parameter forms that can be accepted when creating colors
McCmColorJSON
Ƭ McCmColorJSON: ExcludePropertiesContainingThisType
<McCmColor
, Function
>
The JSON version of McCMColor
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 transformation methods
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
Name | Type |
---|---|
error | string |
ok | boolean |
var | any |
Example
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
}
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
Name | Type | Description |
---|---|---|
`... Ages | [CreateColorArgs ] (2d. md # creatcolors) | Color parameter type |
Returns
Color Object
createMxCad
▸ createMxCad(config?
, mxcadobj?
): Promise
<McObject
>
Create MxCad instance
Parameters
Name | Type | Description |
---|---|---|
config? | [MxCadConfig ] (../interfaces/2d. MxCadConfig. md) | Parameter Configuration |
mxcadobj? | [McObject] (../classes/2d. McObject. md) | Object |
Returns
Example
//Create an instance to display the drawings using the Vite packaging tool
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
Name | Type | Description |
---|---|---|
`... Ages | [THREEColorArgs] (2d. md # threecolorArgs) | Color Parameters |
Returns
Color
THREE.Color
getFilterImp
▸ getFilterImp(filter?
): any
Retrieve a CAD (Computer Aided Design) filter
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Filter | null | [MxCADResbuff] (../classes/2d. MxCADResbuff. md) | null |
Returns
any
CAD filter imp
Example
import { getFilterImp, MxCADResbuf } from 'mxcad';
//Retrieve CAD filter when filter is null
const filterImp1 = getFilterImp();
console.log("Filter Implementation 1:", filterImp1);
//Example 2: Retrieve CAD filter when providing filter
const filter = new MxCADResbuf(); // Assuming you have a MxCADResbuf object
//MxCADResbuf has a method getImp() that returns imp
const filterImp2 = getFilterImp(filter);
console.log("Filter Implementation 2:", filterImp2);
loadMxCADassembly
▸ loadMxCADassembly(call?
, locateFile?
, wasmBinary?
, fontspath?
, networkFonts?
): Promise
<MxCppType
>
Asynchronous loading of MxCAD assembly and execution of callback function after loading completion
Parameters
Name | Type | Description |
---|---|---|
call? | (MxCpp: [MxCppType] (../classes/2d. MxCppType. md)=>void | callback function, executed after loading is complete |
locateFile | (fileName : string , base : string | [URL ]( https://developer.mozilla.org/docs/Web/API/URL ))The 'string' function 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 )Wasm binary data | |
fontspath? | String | Path to font file |
networkFonts? | String [] | Array of network fonts |
Returns
Return a Promise object containing an instance of type MxCppType
Example
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
Name | Type | Description |
---|---|---|
McCmColor | [McCMColor] (../classes/2d. McCMColor. md) | Color Object |
`... Ages | [CreateColorArgs ] (2d. md # creatcolors) | Color parameter type |
Returns
void