[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
import { MxCpp } from "mxcad";
const McAppType = MxCpp.App;Table of contents
Constructors
Methods
- GetVersionDateString
- IniSet
- addNetworkLoadingBigFont
- addNetworkLoadingFont
- addNetworkLoadingTrueTypeFont
- createCloneObject
- destroyObject
- getCurrentMxCAD
- getImp
- getLastCallResult
- getShxBigFonts
- getShxFonts
- getTrueTypeFonts
- getVersionString
- init
- isAlreadyLoaded
- 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 ini. UseUtf8: Does the C++program use the utf8 encoding format. Ini.McGeTol: The precision range for determining whether point and vector variables are equal during geometric calculations, with a default value of 1.0E-7. Ini.Enable Object Modification Event: 1. Enable object to be added, delete notification event, 2: Enable object to be modified notification event, default value is 0 |
Returns
boolean
Example
addNetworkLoadingBigFont
▸ addNetworkLoadingBigFont(fontfiles, fontFilesLoadOnInitialization?, isAddTo?): void
Configure the bigfont 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.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 |
| FontzhName | string [] | undefined | Chinese font name |
| Fontfile | string [] | undefined | Load font file |
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");
}createCloneObject
▸ createCloneObject(clonobjImp): null | McDbObject
Create a cloned object.
Parameters
| Name | Type | Description |
|---|---|---|
| ClonojImp | any | The object that has been cloned. |
Returns
null | McDbObject
Return the created McDbObject object.
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); //Convert object ID to McDbObject object
const obj_clone = MxCpp.App.createCloneObject(obj?.getImp()); //Clone target objectdestroyObject
▸ destroyObject(pObject): void
Destruction of objects.
Parameters
| Name | Type | Description |
|---|---|---|
| PObject | McRxObject Imp | Object to be destroyed. |
Returns
void
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 to "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
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
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
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
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
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
import { MxCpp } from "mxcad";
const version = MxCpp.App.getVersionString();
Console.log ("version information", version);init
▸ init(imp): void
Initialize the McAppType object.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | The imp object passed in. |
Returns
void
Example
import { MxCpp } from "mxcad";
const imp = MxCpp.App.getImp();
MxCpp.App.init(imp);isAlreadyLoaded
▸ isAlreadyLoaded(sFont, iType?): boolean
Obtain whether the font has been loaded from the internet
Parameters
| Name | Type | Default value |
|---|---|---|
sFont | string | undefined |
iType | number | 0 |
Returns
boolean
boolean
Example
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.
Example
import { MxCpp } from 'mxcad'
const colorIndex = MxCpp.App.mcedRGB2Index(255, 0, 0, bAutoNearest)newMcObjectId
▸ newMcObjectId(id?, type?): McObjectId
Create a new McObjectid object.
Parameters
| Name | Type |
|---|---|
id? | number |
type? | McObjectIdType |
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.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
Example
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
Example
import { MxCpp } from 'mxcad'
MxCpp.App.setDefaultViewBackgroundColor(0, 0, 0)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
Example
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
Example
