Skip to content

[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:

  1. Obtain instances through 'MxCpp. App';
  2. Use getCurrentMxCAD() to obtain the current CAD object;
  3. Call methods such as font, background, and object conversion for global configuration and runtime control.

Example

ts
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 ​

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 ​

NameTypeDescription
InianyInitial setting value

Returns ​

boolean

Description

Ini initial setting value

Ini Object NameTypeDescription
UseUtf8booleanDoes the C++program use the utf8 encoding format.
McGeTolnumberThe accuracy of determining the equality between geometric calculation points and vectors is set to 1.0E-7 by default.
EnableObjectModificationEventnumber1 Enable object addition/deletion notification events, '2' enable object modification notification events, default value is' 0 '.
SupportTruetypeFontbooleanDoes it support TruetypeFont? The default value is' true '.
BlockReferenceExGripbooleanWhether the external gripper of the block reference is enabled, the default value is' false '.
Enable 3DbooleanWhether to enable 3D functionality, default value is' false '.
ShowLayoutBackground PaperbooleanWhether the layout background paper is displayed, the default value is true.
LayoutBackground ColornumberLayout 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

ts
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 ​

NameTypeDefault valueDescription
Fontfilesstring \string []undefined
fontFilesLoadOnInitializationstring [][]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

ts
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 ​

NameTypeDefault valueDescription
Fontfilesstring \string []undefined
fontFilesLoadOnInitializationstring[][]-
isAddTobooleanfalse-

Returns ​

void

Example

ts
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 ​

NameTypeDefault valueDescription
Fontnamestring []undefinedfont name array
FontzhNamestring []undefinedChinese font name array
Fontfilestring []undefinedLoad font file array
fontNamesLoadOnInitializationstring[][]-

Returns ​

void

Example

ts
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 ​

McObject

Return the current McObject object.

Example

ts
//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 ​

NameType
impany

Returns ​

void


isAlreadyLoaded ​

▸ isAlreadyLoaded(sFont, iType?): boolean

Obtain whether the font has been loaded from the internet

Parameters ​

NameTypeDefault valueDescription
SFontstringundefinedfont name
ITypenumber0font 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 ​

NameTypeDescription
vecShxFontsstring[]-
vecBigShxFontsstring[]-
VecTureTypeFontsstring []Truetype fonts
RetCall()=>voidcallback function

Returns ​

void

Example

ts
 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 ​

NameTypeDefault valueDescription
Rednumberundefinedred value
GreennumberundefinedGreen value
Bluenumberundefinedblue value
BAutoNearestbooleantrueAutomatically retrieve the most recent color value

Returns ​

number

Return the converted index value.


newMcObjectId ​

▸ newMcObjectId(id?, type?): McObjectId

Create a new McObjectid object.

Parameters ​

NameTypeDescription
ID?numberObject ID
type? [McObject IdType] (../enums/2d. McObject IdType. md)Object Type

Returns ​

McObjectId

Return the newly created McObjectid


objectIdIsKindOf ​

▸ objectIdIsKindOf(lIdIndex, className): boolean

Determine whether an object ID refers to a class type name object

Parameters ​

NameTypeDescription
LIdIDEXNumberObject ID Index
ClassNamestringObject Name

Returns ​

boolean

Return Boolean value

Example

ts
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 ​

NameTypeDescription
The ID of the 'lIdInDdex''number'object

Returns ​

null | McDbObject

Return the converted McDbObject object, and if the conversion fails, return null.

Example

ts
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 ​

NameType
sShxFilestring
sBigShxFilestring

Returns ​

void

Example

ts
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 ​

NameTypeDescription
STrueTypeFontNamestringTrueType font name

Returns ​

void

Example

ts
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 ​

NameTypeDescription
RedNumberRed value
GreenNumberGreen value
BlueNumberBlue value

Returns ​

void


setFontFilePath ​

▸ setFontFilePath(path): void

Configure font loading location, default value is fonts

Parameters ​

NameTypeDescription
PathstringFont file path

Returns ​

void


setImp ​

▸ setImp(imp): void

Set the imp object for McAppType.

Parameters ​

NameTypeDescription
'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 ​

NameType
dTolnumber

Returns ​

number