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

Example

ts

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. ini.EnableObjectModificationEvent: 1. Enable object to be added, delete notification event, 2: Enable object to be modified notification event, default value is 0

Returns

boolean


addNetworkLoadingBigFont

addNetworkLoadingBigFont(fontfiles, fontFilesLoadOnInitialization?, isAddTo?): void

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

Example

ts
import { MxCpp } from 'mxcad'
import { MxFun } from "mxdraw";

//MxCAD created successfully
MxFun.on("mxcadApplicationCreatedMxCADObject", () => {
  MxCpp.App.addNetworkLoadingBigFont(["hztxt.shx", "gbcbig.shx"]);
}

Parameters

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

Returns

void


addNetworkLoadingFont

addNetworkLoadingFont(fontfiles, fontFilesLoadOnInitialization?, isAddTo?): void

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

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"]);
}

Parameters

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

Returns

void


addNetworkLoadingTrueTypeFont

addNetworkLoadingTrueTypeFont(fontname, fontzhName, fontfile, fontNamesLoadOnInitialization?): void

Configure Truetype fonts that need to be loaded through the network

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");
}

Parameters

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

Returns

void


createCloneObject

createCloneObject(clonobjImp): null | McDbObject

Create a cloned 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

Parameters

NameTypeDescription
ClonojImpanyThe object that has been cloned

Returns

null | McDbObject

Return the created McDbObject 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.

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");
}

Returns

McObject

Return the current McObject object.


getImp

getImp(): any

Retrieve the imp object.

Example

ts
import { MxCpp } from "mxcad";

const imp = MxCpp.App.getImp()

Returns

any

Return the imp object.


getLastCallResult

getLastCallResult(): number

Get the result of the last call.

Example

ts
import { MxCpp } from "mxcad";

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

Returns

number

Return the result of the last call


getShxBigFonts

getShxBigFonts(): string[]

Get all currently supported bigfont shx fonts

Example

ts
import { MxCpp } from "mxcad";

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

Returns

string[]

Font array


getShxFonts

getShxFonts(): string[]

Get all currently supported shx fonts

Example

ts
import { MxCpp } from "mxcad";

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

Returns

string[]

Font array


getTrueTypeFonts

getTrueTypeFonts(): { file: string ; name: string ; zhname: string }[]

Get all currently supported TrueType fonts

Example

ts
import { MxCpp } from "mxcad";

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

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

Example

ts
import { MxCpp } from "mxcad";

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

Returns

string

Version information


init

init(imp): void

Initialize the McAppType object.

Example

ts
import { MxCpp } from "mxcad";

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

Parameters

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

Returns

void


isAlreadyLoaded

isAlreadyLoaded(sFont, iType?): boolean

Obtain whether the font has been loaded from the internet

Example

ts

Parameters

NameTypeDefault value
sFontstringundefined
iTypenumber0

Returns

boolean

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

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();
   });
 }

Parameters

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

Returns

void


mcedRGB2Index

mcedRGB2Index(red, green, blue, bAutoNearest?): number

Convert RGB values to indexes.

Example

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

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

NameType
id?number
type?McObjectIdType

Returns

McObjectId

Return the newly created McObjectid


objectIdIsKindOf

objectIdIsKindOf(lIdIndex, className): boolean

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

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")
}

Parameters

NameTypeDescription
LIdIDEXNumberObject ID Index
ClassNamestringObject Name

Returns

boolean

Return Boolean value


objectIdToObject

objectIdToObject(lIdIndex): null | McDbObject

Convert the object ID to a 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);
console.log(obj)

Parameters

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

Returns

null | McDbObject

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


restoreMcGeTol

restoreMcGeTol(): void

The default accuracy range value for determining whether point and vector variables are equal when restoring geometric calculations

Example

ts

Returns

void


setDefaultTrueTypeFontFile

setDefaultTrueTypeFontFile(sTrueTypeFontName): void

Configure default TrueType fonts

Example

ts
import { MxCpp } from "mxcad";
//Set the default TrueType font to Arial.ttf
MxCpp.setDefaultTrueTypeFontFile("Arial.ttf");

Parameters

NameTypeDescription
STrueTypeFontNamestringTrueType font name

Returns

void


setDefaultViewBackgroundColor

setDefaultViewBackgroundColor(red, green, blue): void

Set the default viewport background color

Example

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

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


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

Example

ts

Parameters

NameType
dTolnumber

Returns

number