Skip to content

[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:

  1. Inherit 'McDbCustomEntity' and read fields in 'dwgInFields()';
  2. Write the object properties back to the filter in 'dwgOutFields()';
  3. 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

ts
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

Constructors

constructor

new IMcDbDwgFiler(type)

Constructor function

Parameters

NameTypeDescription
Type[MxCADCloneType] (../enums/2d. MxCADCloneType. md)Clone Type

Methods

getType

getType(): MxCADCloneType

Retrieve the type information of the object

Returns

MxCADCloneType

Clone type


readDouble

Abstract readDouble(name): Object

Read a floating-point number from an open DWG file.

Parameters

NameTypeDescription
NameStringFloating Point Number Name

Returns

Object

Whether ret successfully obtained | val floating-point value

NameType
retboolean
valnumber

readLong

Abstract readLong(name): Object

Read a long integer from the opened DWG file.

Parameters

NameTypeDescription
NamestringLong integer name

Returns

Object

Whether ret successfully obtained | val long integer value

NameType
retboolean
valnumber

readPoint

Abstract readPoint(name): Object

Read a point object from an open DWG file.

Parameters

NameTypeDescription
NameStringPoint Object Name

Returns

Object

Whether ret successfully obtained | val point object array

NameType
retboolean
valMcGePoint3d

readPoints

readPoints(name): Object

Read a set of point objects from an open DWG file.

Parameters

NameTypeDescription
NameStringPoint Object Array Name

Returns

Object

Whether ret successfully obtained | val point object array

NameType
retboolean
valMcGePoint3d[]

readString

Abstract readString(name): Object

Read a string from an open DWG file.

Parameters

NameTypeDescription
NameStringString Name

Returns

Object

Did ret successfully obtain the | val string value

NameType
retboolean
valstring

writeDouble

Abstract writeDouble(name, val): void

Write a floating-point number to an opened DWG file.

Parameters

NameTypeDescription
NameStringFloating Point Number Name
ValnumberFloating point numerical value

Returns

void


writeLong

Abstract writeLong(name, val): void

Write a long integer to an opened DWG file.

Parameters

NameTypeDescription
NamestringLong integer name
Valnumberlong integer value

Returns

void


writePoint

Abstract writePoint(name, val): void

Write a point object to an opened DWG file.

Parameters

NameTypeDescription
NameStringPoint 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

NameTypeDescription
NameStringPoint Object Array Name
ValsMcGePoint3d (2d. McGePoint3d. md)Point Object Array

Returns

void


writeString

Abstract writeString(name, val): void

Write a string to an opened DWG file.

Parameters

NameTypeDescription
NameStringString Name
Valstringstring value

Returns

void