Skip to content
On this page

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

Class: McAppType

2d.McAppType

The McAppType class provides some basic operations for MxCAD.

Example

ts
import { MxCpp } from "mxcad";

const McAppType = MxCpp.App;

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 ini UseUtf8: Does the C++program use the Utf8 encoding format. ini.McGeTol: The accuracy range for determining whether point and vector variables are equal in geometric calculations is 1.0E-7 by default

Returns

boolean

Example

ts

addNetworkLoadingBigFont

addNetworkLoadingBigFont(fontfiles, fontFilesLoadOnInitialization?): void

Configure the bigfont shx font that needs to be loaded through the network

Parameters

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

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?): void

Configure the shx font that needs to be loaded through the network

Parameters

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

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
FontzhNamestring []undefinedChinese font name
Fontfilestring []undefinedLoad font file
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");
}

createCloneObject

createCloneObject(clonobjImp): null | McDbObject

Create a cloned object.

Parameters

NameTypeDescription
ClonojImpanyThe object that has been cloned

Returns

null | McDbObject

Return the created McDbObject object.

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);//  Convert object ID to McDbObject object
const obj_clone = MxCpp.App.createCloneObject(obj?.getImp());//  Clone target object

destroyObject

destroyObject(pObject): void

Destruction of objects.

Parameters

NameTypeDescription
PObjectMcRxObject ImpObject to be destroyed

Returns

void


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.

Example

ts
import { MxCpp } from "mxcad";

const imp = MxCpp.App.getImp()

getLastCallResult

getLastCallResult(): number

Get the result of the last call.

Returns

number

Return the result of the last call

Example

ts
import { MxCpp } from "mxcad";

const result = MxCpp.App.getLastCallResult();
Console.log (Last call result: ", result);

getShxBigFonts

getShxBigFonts(): string[]

Get all currently supported bigfont shx fonts

Returns

string[]

Font array

Example

ts
import { MxCpp } from "mxcad";

const bigFontArr = MxCpp.App.getShxBigFonts();
console.log(bigFontArr);

getShxFonts

getShxFonts(): string[]

Get all currently supported shx fonts

Returns

string[]

Font array

Example

ts
import { MxCpp } from "mxcad";

const fontArr = MxCpp.App.getShxFonts();
console.log(fontArr);

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

Example

ts
import { MxCpp } from "mxcad";

const trueTypeFontArr = MxCpp.App.getTrueTypeFonts();
console.log(trueTypeFontAr);

getVersionString

getVersionString(): string

Obtain the version information of the current program

Returns

string

Version information

Example

ts
import { MxCpp } from "mxcad";

const version = MxCpp.App.getVersionString();
Console.log ("version information", version);

init

init(imp): void

Initialize the McAppType object.

Parameters

NameTypeDescription
'imp''any'The imp object passed in

Returns

void

Example

ts
import { MxCpp } from "mxcad";

const imp = MxCpp.App.getImp();
MxCpp.App.init(imp);

loadFonts

loadFonts(vecShxFonst, vecBigShxFonst, 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
VecShxFonststring []shx font
VecBigShxFonststring []bigfont shx font
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.

Example

ts
import { MxCpp } from 'mxcad'
const colorIndex = MxCpp.App.mcedRGB2Index(255, 0, 0, bAutoNearest)

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.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

Example

ts

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
MxCpp.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

Example

ts
import { MxCpp } from 'mxcad'
MxCpp.App.setDefaultViewBackgroundColor(0, 0, 0)

setFontFilePath

setFontFilePath(path): void

Configure font loading location, default value is fonts

Parameters

NameTypeDescription
PathstringFont file path

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

Example

ts