[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McAppType
Class: McAppType
2d.McAppType
McAppType is an MxCAD application level core entry class.
Description
This class is responsible for encapsulating the global capabilities of MxCAD runtime, including application initialization, current CAD instance acquisition, color and background settings, font loading, object type conversion, and interaction with underlying C++implementations. It is the main entry point for accessing the global capabilities of MxCAD in plugin and extension development. Summary of usage:
- Obtain instances through 'MxCpp. App';
- Use
getCurrentMxCAD()to obtain the current CAD object; - Call methods such as font, background, and object conversion for global configuration and runtime control.
Example
import { MxCpp, McDbLayerTableRecord } from "mxcad";
const app = MxCpp.App;
//Retrieve the current MXCAD object
const mxcad = MxCpp.App.getCurrentMxCAD();
//Set the default viewport background color to white
app.setDefaultViewBackgroundColor(255, 255, 255);
//Set the default font to Arial
app.setDefaultTrueTypeFontFile("Arial.ttf");
//Determine object type
const isCurve = app.objectIdIsKindOf(someId, "McDbCurve");Table of contents
Constructors
Methods
- GetVersionDateString
- IniSet
- addNetworkLoadingBigFont
- addNetworkLoadingFont
- addNetworkLoadingTrueTypeFont
- getCurrentMxCAD
- getImp
- getLastCallResult
- getShxBigFonts
- getShxFonts
- getTrueTypeFonts
- getVersionString
- init
- isAlreadyLoaded
- isWasmx64
- loadFonts
- mcedRGB2Index
- newMcObjectId
- objectIdIsKindOf
- objectIdToObject
- restoreMcGeTol
- setDefaultShxFontFile
- setDefaultTrueTypeFontFile
- setDefaultViewBackgroundColor
- setFontFilePath
- setImp
- setMcGeTol
Constructors
constructor
• new McAppType()
Methods
GetVersionDateString
▸ GetVersionDateString(): string
Obtain the numerical date version information of the current program
Returns
string
Digital date version information
IniSet
▸ IniSet(ini): boolean
Initial setting of global parameters
Parameters
| Name | Type | Description |
|---|---|---|
| Ini | any | Initial setting value |
Returns
boolean
Description
Ini initial setting value
| Ini Object Name | Type | Description |
|---|---|---|
| UseUtf8 | boolean | Does the C++program use the utf8 encoding format. |
| McGeTol | number | The accuracy of determining the equality between geometric calculation points and vectors is set to 1.0E-7 by default. |
EnableObjectModificationEvent | number | 1 Enable object addition/deletion notification events, '2' enable object modification notification events, default value is' 0 '. |
| SupportTruetypeFont | boolean | Does it support TruetypeFont? The default value is' true '. |
| BlockReferenceExGrip | boolean | Whether the external gripper of the block reference is enabled, the default value is' false '. |
| Enable 3D | boolean | Whether to enable 3D functionality, default value is' false '. |
| ShowLayoutBackground Paper | boolean | Whether the layout background paper is displayed, the default value is true. |
| LayoutBackground Color | number | Layout background color, default value is 0xFFFFFF. |
| When the object is displayed as less than the pixel value, it will be directly displayed as a point, with a default value of '1' |
Example
import { MxCpp } from 'mxcad';
//Set global parameters
MxCpp.App.IniSet({SupportTruetypeFont:false, BlockReferenceExGrip:true});addNetworkLoadingBigFont
▸ addNetworkLoadingBigFont(fontfiles, fontFilesLoadOnInitialization?, isAddTo?): void
Configure bigfont fonts that need to be loaded through the network
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Fontfiles | string \ | string [] | undefined |
fontFilesLoadOnInitialization | string [] | [] | Font files that need to be loaded during initialization |
| Is' isAddTo ' | ' boolean ' | ' false 'added to the current font list? The default value is false |
Returns
void
Example
import { MxCpp } from 'mxcad'
import { MxFun } from "mxdraw";
//MxCAD created successfully
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
MxCpp.App.addNetworkLoadingBigFont(["hztxt.shx", "gbcbig.shx"]);
}addNetworkLoadingFont
▸ addNetworkLoadingFont(fontfiles, fontFilesLoadOnInitialization?, isAddTo?): void
Configure the shx font that needs to be loaded through the network
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Fontfiles | string \ | string [] | undefined |
fontFilesLoadOnInitialization | string[] | [] | - |
isAddTo | boolean | false | - |
Returns
void
Example
import { MxCpp } from 'mxcad';
import { MxFun } from "mxdraw";
//MxCAD created successfully
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
MxCpp.App.addNetworkLoadingFont( ["txt.shx","simplex.shx","aaa.shx","ltypeshp.shx","complex.shx"]);
}addNetworkLoadingTrueTypeFont
▸ addNetworkLoadingTrueTypeFont(fontname, fontzhName, fontfile, fontNamesLoadOnInitialization?): void
Configure Truetype fonts that need to be loaded through the network
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Fontname | string [] | undefined | font name array |
| FontzhName | string [] | undefined | Chinese font name array |
| Fontfile | string [] | undefined | Load font file array |
fontNamesLoadOnInitialization | string[] | [] | - |
Returns
void
Example
import { MxCpp } from 'mxcad'
import { MxFun } from "mxdraw";
//MxCAD created successfully
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
MxCpp. App. addNetworkLoadingTrueTypeFont (["simsun", "syadobe"], ["siyuan songti", "siyuan blackbody"], ["stadobe. otf", "syadobe. otf");
}getCurrentMxCAD
▸ getCurrentMxCAD(): McObject
Retrieve the current MxDraw object.
Returns
Return the current McObject object.
Example
//Add Layer
import { MxCpp } from 'mxcad'
//Retrieve the current CAD object
let mxcad = MxCpp.App.getCurrentMxCAD();
//Get layer table
let layerTable = mxcad.getDatabase().getLayerTable();
if (!layerTable.has("xxx11")) {
let newLayer = new McDbLayerTableRecord();// Construct a new layer to record objects
newLayer.name = "xxx11";// Set the new layer name as: "xxx11"
layerTable.add(newLayer);// Add layer record objects to the layer table
}
if (layerTable.has("xxx11")) {
console.log("add layer ok");
}getImp
▸ getImp(): any
Retrieve the imp object.
Returns
any
Return the imp object.
getLastCallResult
▸ getLastCallResult(): number
Get the result of the last call.
Returns
number
Return the result of the last call
getShxBigFonts
▸ getShxBigFonts(): string[]
Get all currently supported bigfont shx fonts
Returns
string[]
Font array
getShxFonts
▸ getShxFonts(): string[]
Get all currently supported shx fonts
Returns
string[]
Font array
getTrueTypeFonts
▸ getTrueTypeFonts(): { file: string ; name: string ; zhname: string }[]
Get all currently supported TrueType fonts
Returns
{ file: string ; name: string ; zhname: string }[]
Name Font Name | zhname Font Chinese Name | file Font File
getVersionString
▸ getVersionString(): string
Obtain the version information of the current program
Returns
string
Version information
init
▸ init(imp): void
Initialize the McAppType object.
Parameters
| Name | Type |
|---|---|
imp | any |
Returns
void
isAlreadyLoaded
▸ isAlreadyLoaded(sFont, iType?): boolean
Obtain whether the font has been loaded from the internet
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| SFont | string | undefined | font name |
| IType | number | 0 | font type 0: shx font 1: bigshx font 2: truetype font |
Returns
boolean
boolean
isWasmx64
▸ isWasmx64(): boolean
Returns
boolean
loadFonts
▸ loadFonts(vecShxFonts, vecBigShxFonts, vecTureTypeFonts, retCall): void
Notify the CAD program that the fonts to be used in the future need to be loaded for ease of use in subsequent programs
Parameters
| Name | Type | Description |
|---|---|---|
vecShxFonts | string[] | - |
vecBigShxFonts | string[] | - |
| VecTureTypeFonts | string [] | Truetype fonts |
| RetCall | ()=>void | callback function |
Returns
void
Example
import { MxCpp } from 'mxcad';
//Modify Text Style
function Mx_Test_TrueText(){
let mxcad = MxCpp.getCurrentMxCAD();
//Clear the current display content
mxcad.newFile();
MxCpp.App.loadFonts([], [], ["syadobe","simsun"], () => {
//Add a bold text style
mxcad.AddTureTypeTextStyle("ht_style","syadobe");
//Add a Song typeface text style
mxcad.AddTureTypeTextStyle("st_style","simsun");
//Set the current style to bold
mxcad.drawTextStyle = "ht_style";
mxcad.drawColor = new McCmColor(200, 255, 50);
Let idText=mxcad.drawText (0, 3500, "TrueType Text Test for Drawing Control", 100, 0, 0, 1);
let ent = idText.getMcDbEntity();
//Change the text style to Song typeface
if(ent) ent.textStyle = "st_style";
mxcad.zoomAll();
mxcad.regen();
mxcad.updateDisplay();
});
}mcedRGB2Index
▸ mcedRGB2Index(red, green, blue, bAutoNearest?): number
Convert RGB values to indexes.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Red | number | undefined | red value |
| Green | number | undefined | Green value |
| Blue | number | undefined | blue value |
| BAutoNearest | boolean | true | Automatically retrieve the most recent color value |
Returns
number
Return the converted index value.
newMcObjectId
▸ newMcObjectId(id?, type?): McObjectId
Create a new McObjectid object.
Parameters
| Name | Type | Description |
|---|---|---|
| ID? | number | Object ID |
type? | [McObject IdType] (../enums/2d. McObject IdType. md) | Object Type |
Returns
Return the newly created McObjectid
objectIdIsKindOf
▸ objectIdIsKindOf(lIdIndex, className): boolean
Determine whether an object ID refers to a class type name object
Parameters
| Name | Type | Description |
|---|---|---|
| LIdIDEX | Number | Object ID Index |
| ClassName | string | Object Name |
Returns
boolean
Return Boolean value
Example
import { MxCADUiPrEntity } from "mxcad";
//Select target object
let selEntity = new MxCADUiPrEntity();
SelEntity. setMessage ("Select Object");
let val = await selEntity.go();
if (!val.isValid()) return;
//Determine if the target object is a polyline class
const isSuccess = MxCpp.App.objectIdIsKindOf(val.id, "McDbPolyline");
if(isSuccess){
Console.log ("Target object is polyline")
}else{
Console.log ("Target object is not a polyline")
}objectIdToObject
▸ objectIdToObject(lIdIndex): null | McDbObject
Convert the object ID to a McDbObject object.
Parameters
| Name | Type | Description |
|---|---|---|
| The ID of the 'lIdInDdex' | 'number' | object |
Returns
null | McDbObject
Return the converted McDbObject object, and if the conversion fails, return null.
Example
import { MxCADUiPrEntity, MxCpp } from "mxcad";
//Obtain the target object
let selEntity = new MxCADUiPrEntity();
let val = await selEntity.go();
if (!val.isValid()) return;
const obj = MxCpp.App.objectIdToObject(val.id);
console.log(obj)restoreMcGeTol
▸ restoreMcGeTol(): void
The default accuracy range value for determining whether point and vector variables are equal when restoring geometric calculations
Returns
void
setDefaultShxFontFile
▸ setDefaultShxFontFile(sShxFile, sBigShxFile): void
Configure default shx and bigshx fonts
Parameters
| Name | Type |
|---|---|
sShxFile | string |
sBigShxFile | string |
Returns
void
Example
import { MxCpp } from "mxcad";
mxcad.on("init_cpp", async () => {
MxCpp.App.setDefaultShxFontFile("txt.shx","hztxt.shx");
})setDefaultTrueTypeFontFile
▸ setDefaultTrueTypeFontFile(sTrueTypeFontName): void
Configure default TrueType fonts
Parameters
| Name | Type | Description |
|---|---|---|
| STrueTypeFontName | string | TrueType font name |
Returns
void
Example
import { MxCpp } from "mxcad";
//Set the default TrueType font to Arial.ttf
mxcad.on("init_cpp", async () => {
MxCpp.App.setDefaultTrueTypeFontFile("Arial.ttf");
})setDefaultViewBackgroundColor
▸ setDefaultViewBackgroundColor(red, green, blue): void
Set the default viewport background color
Parameters
| Name | Type | Description |
|---|---|---|
| Red | Number | Red value |
| Green | Number | Green value |
| Blue | Number | Blue value |
Returns
void
setFontFilePath
▸ setFontFilePath(path): void
Configure font loading location, default value is fonts
Parameters
| Name | Type | Description |
|---|---|---|
| Path | string | Font file path |
Returns
void
setImp
▸ setImp(imp): void
Set the imp object for McAppType.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | The imp object passed in |
Returns
void
setMcGeTol
▸ setMcGeTol(dTol): number
When setting geometric calculations, the accuracy range for determining whether point and vector variables are equal is set to 1.0E-7 by default
Parameters
| Name | Type |
|---|---|
dTol | number |
Returns
number
