[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbDatabase
Class: McDbDatabase
2d.McDbDatabase
Represents a database. All information in the graph is stored in this object. Call the mxcad. getDatabase() function to get the database of the control.
Hierarchy
↳
McDbDatabase
Table of contents
Constructors
Properties
Accessors
Methods
- CreateGroup
- GetGroupDictionary
- SetCurrentlyTextStyleId
- getBlockTable
- getCurrentlyColorIndex
- getCurrentlyDimStyleId
- getCurrentlyDrawColor
- getCurrentlyLayerId
- getCurrentlyLayerName
- getCurrentlyLineTypeName
- getCurrentlyLineTypeScale
- getCurrentlyLineWeight
- getCurrentlyLinetypeId
- getCurrentlyTextStyleId
- getCurrentlyTextStyleName
- getCurrentlyTrueColor
- getDimStyleTable
- getEntitiesInTheGroup
- getImp
- getJson
- getLayerTable
- getLinetypeTable
- getNamedObjectsDictionary
- getTextStyleTable
- handleToIdIndex
- initTempObject
- insert
- isKindOf
- isModifyed
- isNull
- readFile
- resetModificationStatus
- saveAs
- setCurrentlyColorIndex
- setCurrentlyDimStyleId
- setCurrentlyLayerId
- setCurrentlyLayerName
- setCurrentlyLineTypeName
- setCurrentlyLineTypeScale
- setCurrentlyLineWeight
- setCurrentlyLinetypeId
- setCurrentlyTextStyle
- setCurrentlyTrueColor
- setJson
- wblock
Constructors
constructor
• new McDbDatabase(imp?
)
Constructor.
Parameters
Name | Type | Description |
---|---|---|
imp? | Any | Internal implementation object |
Overrides
Properties
imp
• imp: any
= 0
Internal implementation object.
Inherited from
Accessors
blockTable
• get
blockTable(): McDbBlockTable
Get block table
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let blkTable = dataBase.blockTable;
currentSpace
• get
currentSpace(): McDbBlockTableRecord
Return the current space block table record
Returns
Block table record
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentBlkRec = dataBase.currentSpace;
dimStyleTable
• get
dimStyleTable(): McDbDimStyleTable
Retrieve the annotation style sheet.
Returns
Linear table.
dxf0
• get
dxf0(): string
Obtain the type name of the object's DXF group code, which is the same as the DXF group code in AutoCAD. For example, the type name of the line is McDbLine, and the group code value for DXF0 is: LINE and DXF0 group code values can be used for type filtering when constructing sets.
Returns
string
Inherited from
McRxObject.dxf0
layerTable
• get
layerTable(): McDbLayerTable
Get layer table
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let layerTable = dataBase.layerTable;
linetypeTable
• get
linetypeTable(): McDbLinetypeTable
Get line type table
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let lineTypeTable = dataBase.linetypeTable;
objectName
• get
objectName(): string
Get the object name.
Returns
string
Return object name
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Inherited from
McRxObject.objectName
textStyleTable
• get
textStyleTable(): McDbTextStyleTable
Get Text Style Sheet
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let textStyleTable = dataBase.textStyleTable;
ucsMatrix
• get
ucsMatrix(): McGeMatrix3d
Obtain the UCS user coordinate system transformation matrix
Returns
Example
• set
ucsMatrix(val
): void
Set UCS user coordinate system transformation matrix
Parameters
Name | Type |
---|---|
val | McGeMatrix3d |
Returns
void
Example
Methods
CreateGroup
▸ CreateGroup(ids
, name?
): boolean
Create a group from a pile of objects
Parameters
Name | Type | Default value |
---|---|---|
ids | McObjectId [] | undefined |
name | string | "" |
Returns
boolean
McDbDictionary
GetGroupDictionary
▸ GetGroupDictionary(): McDbDictionary
Obtain the group dictionary object of the drawing.
Returns
McDbDictionary
Example
___
### SetCurrentlyTextStyleId
▸ **SetCurrentlyTextStyleId**(`id`): `boolean`
Set the current text style id
#### Parameters
| Name | Type |
| :------ | :------ |
| `id` | [`McObjectId`](2d.McObjectId.md) |
#### Returns
`boolean`
___
### getBlockTable
▸ **getBlockTable**(): [`McDbBlockTable`](2d.McDbBlockTable.md)
Retrieve the block table.
#### Returns
[`McDbBlockTable`](2d.McDbBlockTable.md)
Block table.
**`Example`**
```ts
import { MxCpp, McDbDatabase } from "mxcad"
let mxcad = MxCpp.App.getCurrentMxCAD();
let blockTable = mxcad.getDatabase().getBlockTable();
let aryId = blockTable.getAllRecordId();
aryId.forEach((id) => {
let blkRec = id.getMcDbBlockTableRecord();
if (blkRec === null) return;
console.log(blkRec);
console.log("blkRec.name:" + blkRec.name);
console.log("blkRec.origin:" + blkRec.origin);
});
getCurrentlyColorIndex
▸ getCurrentlyColorIndex(): number
Retrieve the current color index.
Returns
number
Current Color Index (ColorIndexType).
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();
getCurrentlyDimStyleId
▸ getCurrentlyDimStyleId(): McObjectId
Return the current annotation style id
Returns
getCurrentlyDrawColor
▸ getCurrentlyDrawColor(): Color
Get the color used in the current drawing
Returns
Color
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyDrawColor();
getCurrentlyLayerId
▸ getCurrentlyLayerId(): McObjectId
Return the current layer ID
Returns
getCurrentlyLayerName
▸ getCurrentlyLayerName(): string
Get the current layer name.
Returns
string
Current layer name.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const layerName = dataBase.getCurrentlyLayerName();
getCurrentlyLineTypeName
▸ getCurrentlyLineTypeName(): string
Get the current line type name.
Returns
string
The current line type name.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const name = dataBase.getCurrentlyLineTypeName();
getCurrentlyLineTypeScale
▸ getCurrentlyLineTypeScale(): number
Get the current line type scale.
Returns
number
Current line type scale.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
let currentLTS = dataBase.getCurrentlyLineTypeScale();
getCurrentlyLineWeight
▸ getCurrentlyLineWeight(): LineWeight
Return the current line weight used
Returns
getCurrentlyLinetypeId
▸ getCurrentlyLinetypeId(): McObjectId
Return the current line type ID
Returns
getCurrentlyTextStyleId
▸ getCurrentlyTextStyleId(): McObjectId
Return the current text style id
Returns
getCurrentlyTextStyleName
▸ getCurrentlyTextStyleName(): string
Get the current text style name.
Returns
string
The current text style name.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const textStyName = dataBase.getCurrentlyTextStyleName();
getCurrentlyTrueColor
▸ getCurrentlyTrueColor(): McCmColor
Retrieve the current CAD color.
Returns
Current CAD color.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = dataBase.getCurrentlyTrueColor();
getDimStyleTable
▸ getDimStyleTable(): McDbDimStyleTable
Retrieve the annotation style sheet.
Returns
Linear table.
getEntitiesInTheGroup
▸ getEntitiesInTheGroup(id
): McObjectId
[]
Get all object IDs in the group where the object is located
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
McDbDictionary
Example
___
### getImp
▸ **getImp**(): `any`
Retrieve internal implementation objects.
#### Returns
`any`
Internal implementation object.
**`Example`**
```ts
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Inherited from
getJson
▸ getJson(): string
Retrieve a string in JSON format.
Returns
string
A string in JSON format.
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Inherited from
getLayerTable
▸ getLayerTable(): McDbLayerTable
Retrieve the layer table.
Returns
Layer table.
Example
import { MxCADUiPrEntity, MxCpp } from "mxcad";
//Hide the layer where the target object is located
async function Mx_SelectEntitHideLayer() {
let selEntity1 = new MxCADUiPrEntity();
SelElement1.setMessage ("Select Objects to Hide")
let id = await selEntity1.go();
if (!id.isValid()) return;
let ent = id.getMcDbEntity();
let mxcad = MxCpp.getCurrentMxCAD();
let layerTable = mxcad.getDatabase().getLayerTable();
let layerId = layerTable.get(ent.layer);
let layerRec = layerId.getMcDbLayerTableRecord();
if (layerRec === null) return;
layerRec.isOff = true;
mxcad.updateLayerDisplayStatus();
mxcad.updateDisplay()
}
getLinetypeTable
▸ getLinetypeTable(): McDbLinetypeTable
Retrieve the line type table.
Returns
Linear table.
Example
import { MxCpp } from "mxcad"
//Get all line types
let mxcad = MxCpp.App.getCurrentMxCAD();
let linetypeTable = mxcad.getDatabase().getLinetypeTable();
let aryId = linetypeTable.getAllRecordId();
aryId.forEach((id) => {
let linetypeRec = id.getMcDbLinetypeTableRecord();
if (linetypeRec === null) return;
console.log(linetypeRec);
});
getNamedObjectsDictionary
▸ getNamedObjectsDictionary(): McDbDictionary
Obtain the dictionary object of the drawing.
Returns
McDbDictionary
Example
import { MxCpp, McDbDatabase } from "mxcad"
//Write extension records
let mxcad = MxCpp.getCurrentMxCAD();
let dict = mxcad.getDatabase().getNamedObjectsDictionary();
let sName = "MyDict";
let idDict = dict.getAt(sName);
if (idDict.isNull()) {
let newDict = new McDbDictionary;
idDict = dict.addObject(sName, newDict);
}
let myDict = idDict.getMcDbDictionary();
if (myDict) {
let xrec = new McDbXrecord();
let data = new MxCADResbuf();
data.AddString("TestData");
xrec.setData(data);
myDict.addObject("MyRecord", xrec);
console.log("write xrecord ok");
}
getTextStyleTable
▸ getTextStyleTable(): McDbTextStyleTable
Retrieve the text style sheet.
Returns
Text style sheet.
Example
//Get all text styles
import { MxCpp } from "mxcad"
let mxcad = MxCpp.getCurrentMxCAD();
let textSyleTable = mxcad.getDatabase().getTextStyleTable();
let aryId = textSyleTable.getAllRecordId();
aryId.forEach((id) => {
let textSyleRec = id.getMcDbTextStyleTableRecord();
if (textSyleRec === null) return;
let out: any = {};
out.name = textSyleRec.name;
out.font = textSyleRec.font();
out.fileName = textSyleRec.fileName;
out.bigFontFileName = textSyleRec.bigFontFileName;
out.textSize = textSyleRec.textSize;
out.xScale = textSyleRec.xScale;
console.log(out);
});
handleToIdIndex
▸ handleToIdIndex(sHandle
): McObjectId
Return the object ID based on the handle of the object
Parameters
Name | Type |
---|---|
sHandle | string |
Returns
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
//Pass in the handle and obtain the corresponding object ID
const handle = "ABCD1234"; // Assuming this is a valid handle
const objectId = dataBase.handleToIdIndex(handle);
//Ensure that the obtained object ID is valid
if (objectId) {
console.log("success", objectId);
} else {
console.log("error")
}
initTempObject
▸ initTempObject(imp
): void
Initialize temporary objects.
Parameters
Name | Type | Description |
---|---|---|
'imp' | 'any' | Internal implementation object |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Inherited from
insert
▸ insert(database
, sBlkName
): McObjectId
Insert block
Parameters
Name | Type |
---|---|
database | McDbDatabase |
sBlkName | string |
Returns
Example
isKindOf
▸ isKindOf(sObjectName
): boolean
Determine object type
Parameters
Name | Type | Description |
---|---|---|
SOrtName | string | Type Name |
Returns
boolean
Return whether the object is of the target type
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // Output: True or false
Inherited from
isModifyed
▸ isModifyed(): boolean
Has the current database been modified
Returns
boolean
Return Boolean value
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const res = dataBase.isModifyed();
if(res){
Console.log ("Modified")
}else{
Console.log ("unmodified")
}
isNull
▸ isNull(): any
Determine if it is an empty object
Returns
any
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.isNull()); // Output: True or false
Inherited from
readFile
▸ readFile(sFilePath
): boolean
Read files.
Parameters
Name | Type |
---|---|
sFilePath | string |
Returns
boolean
Example
resetModificationStatus
▸ resetModificationStatus(): void
Reset the current database modification status to unmodified status
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.resetModificationStatus();
saveAs
▸ saveAs(sFilePath
): boolean
Save the file.
Parameters
Name | Type |
---|---|
sFilePath | string |
Returns
boolean
Example
setCurrentlyColorIndex
▸ setCurrentlyColorIndex(colorIndex
): any
Set the current color index (ColorIndexType).
Parameters
Name | Type | Description |
---|---|---|
ColorIndex | Number | Color Index |
Returns
any
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const colorIndex = dataBase.getCurrentlyColorIndex();
setCurrentlyDimStyleId
▸ setCurrentlyDimStyleId(id
): boolean
Set the current annotation style id
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyLayerId
▸ setCurrentlyLayerId(id
): boolean
Set the current annotation style id
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyLayerName
▸ setCurrentlyLayerName(sName
): void
Set the current layer name.
Parameters
Name | Type | Description |
---|---|---|
SName | string | layer name |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase. setCurrentlyLayerName ("Test Layer");
setCurrentlyLineTypeName
▸ setCurrentlyLineTypeName(sName
): void
Set the current line type name.
Parameters
Name | Type | Description |
---|---|---|
SName | string | Line type name |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase. setCurrentlyLineTypeName ("test line type");
setCurrentlyLineTypeScale
▸ setCurrentlyLineTypeScale(val
): number
Set the current line type scale.
Parameters
Name | Type | Description |
---|---|---|
Val | number | Line proportion |
Returns
number
Current line type scale.
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
dataBase.setCurrentlyLineTypeScale(0.8);
setCurrentlyLineWeight
▸ setCurrentlyLineWeight(lineWeight
): void
Set the current line weight used
Parameters
Name | Type |
---|---|
lineWeight | LineWeight |
Returns
void
setCurrentlyLinetypeId
▸ setCurrentlyLinetypeId(id
): boolean
Set the current annotation style id
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
boolean
setCurrentlyTextStyle
▸ setCurrentlyTextStyle(sName
): void
Set the current text style name.
Parameters
Name | Type | Description |
---|---|---|
SName | string | Text style name |
Returns
void
Example
import { MxCpp, McDbDatabase } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
DataBase.setCurrentlyStyle ("Test Text Style");
setCurrentlyTrueColor
▸ setCurrentlyTrueColor(color
): any
Set the current CAD color.
Parameters
Name | Type | Description |
---|---|---|
Color | [McCMColor] (2d. McCmColor. md) | CAD color |
Returns
any
Example
import { MxCpp, McDbDatabase, McCmColor } from "mxcad"
const dataBase:McDbDatabase = MxCpp.getCurrentMxCAD().getDatabase();
const color = new McCmColor(255, 0, 0);
dataBase.setCurrentlyTrueColor(color);
setJson
▸ setJson(str
): boolean
Set a string in JSON format.
Parameters
Name | Type | Description |
---|---|---|
Str | string | JSON formatted string |
Returns
boolean
Is the setting successful.
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)
Inherited from
wblock
▸ wblock(database
, aryId
, ptBase?
): boolean
Write a block
Parameters
Name | Type |
---|---|
database | McDbDatabase |
aryId | McObjectId [] |
ptBase? | McGePoint3d |
Returns
boolean
Example