[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/IMcDbDwgFiler
Class: IMcDbDwgFiler
2d.IMcDbDwgFiler
DWG field read-write interface, used to synchronize attribute data between custom entities and AutoCAD file formats.
Description
This class provides a unified field access interface for writing or reading geometric and attribute data from custom entities into DWG files by name. In custom entity development, it is usually necessary to implement: -WritePoint/ReadPoint: Processing McGePoint3d type fields; -WritePoints/readPoints: Processing point array fields; -WriteLong/readLong: Processing integer values; -WriteDouble/ReadDouble: Processing floating-point numbers; -WriteString/readString: Processing strings.
Through this interface, developers can ensure that custom entities maintain data consistency when saving, cloning, and loading DWG files, avoiding runtime state loss.
Usage:
- Inherit 'McDbCustomEntity' and read fields in 'dwgInFields()';
- Write the object properties back to the filter in 'dwgOutFields()';
- Implement object persistence and recovery by combining custom entity registration and drawing logic.
Summary: 'IMcDbDwgFiler' is a bridging interface for custom entity data persistence, responsible for converting JavaScript side object states with field data in DWG files.
Example
import { McDbCustomEntity, IMcDbDwgFiler, McGePoint3d } from "mxcad";
class McDbTestLineCustomEntity extends McDbCustomEntity {
private pt1: McGePoint3d = new McGePoint3d();
private pt2: McGePoint3d = new McGePoint3d();
public create(imp?: any): McDbCustomEntity {
return new McDbTestLineCustomEntity(imp);
}
public getTypeName(): string {
return "McDbTestLineCustomEntity";
}
public dwgInFields(filter: IMcDbDwgFiler): boolean {
this.pt1 = filter.readPoint("pt1").val;
this.pt2 = filter.readPoint("pt2").val;
return true;
}
public dwgOutFields(filter: IMcDbDwgFiler): boolean {
filter.writePoint("pt1", this.pt1);
filter.writePoint("pt2", this.pt2);
return true;
}
public worldDraw(draw: any): void {
//Customize drawing logic
}
}Table of contents
Constructors
Methods
- getType
- readDouble
- readLong
- readPoint
- readPoints
- readString
- writeDouble
- writeLong
- writePoint
- writePoints
- writeString
Constructors
constructor
• new IMcDbDwgFiler(type)
Constructor function
Parameters
| Name | Type | Description |
|---|---|---|
| Type | [MxCADCloneType] (../enums/2d. MxCADCloneType. md) | Clone Type |
Methods
getType
▸ getType(): MxCADCloneType
Retrieve the type information of the object
Returns
Clone type
readDouble
▸ Abstract readDouble(name): Object
Read a floating-point number from an open DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Floating Point Number Name |
Returns
Object
Whether ret successfully obtained | val floating-point value
| Name | Type |
|---|---|
ret | boolean |
val | number |
readLong
▸ Abstract readLong(name): Object
Read a long integer from the opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | string | Long integer name |
Returns
Object
Whether ret successfully obtained | val long integer value
| Name | Type |
|---|---|
ret | boolean |
val | number |
readPoint
▸ Abstract readPoint(name): Object
Read a point object from an open DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Point Object Name |
Returns
Object
Whether ret successfully obtained | val point object array
| Name | Type |
|---|---|
ret | boolean |
val | McGePoint3d |
readPoints
▸ readPoints(name): Object
Read a set of point objects from an open DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Point Object Array Name |
Returns
Object
Whether ret successfully obtained | val point object array
| Name | Type |
|---|---|
ret | boolean |
val | McGePoint3d[] |
readString
▸ Abstract readString(name): Object
Read a string from an open DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | String Name |
Returns
Object
Did ret successfully obtain the | val string value
| Name | Type |
|---|---|
ret | boolean |
val | string |
writeDouble
▸ Abstract writeDouble(name, val): void
Write a floating-point number to an opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Floating Point Number Name |
| Val | number | Floating point numerical value |
Returns
void
writeLong
▸ Abstract writeLong(name, val): void
Write a long integer to an opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | string | Long integer name |
| Val | number | long integer value |
Returns
void
writePoint
▸ Abstract writePoint(name, val): void
Write a point object to an opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Point Object Name |
| Val | [McGePoint3d] (2d. McGePoint3d. md) | Point Object |
Returns
void
writePoints
▸ writePoints(name, vals): void
Write a set of point objects to an opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | Point Object Array Name |
| Vals | McGePoint3d (2d. McGePoint3d. md) | Point Object Array |
Returns
void
writeString
▸ Abstract writeString(name, val): void
Write a string to an opened DWG file.
Parameters
| Name | Type | Description |
|---|---|---|
| Name | String | String Name |
| Val | string | string value |
Returns
void
