Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDbObject Array

Class: McDbObjectArray

2d.McDbObjectArray

McDbObject Array is a collection container for multiple McDbObject objects, used for batch storage, traversal, and management of database objects.

Description

This class is suitable for unified processing scenarios of a group of objects, such as batch traversal, filtering, statistics, and subsequent editing. It can accomplish: -Batch save a set of database objects; -Accessing objects by index; -Traverse the array and execute unified logic; -Determine whether the set is empty.

Usage:

  1. Create a McDbObject Array by querying the database or returning a collection of objects;
  2. Call forEach() to traverse each object;
  3. Use length() and empty() to determine the set state;
  4. Continue to convert objects into specific entity types as needed for subsequent processing.

Summary: In practical development, McDbObject Array is mainly used for batch object processing, suitable for scenarios that require unified traversal, filtering, or statistics of a set of database objects.

Example

  • ts
      * import { MxCADUiPrPoint, MxCpp, MxCADUiPrEntity, McDbObject } from 'mxcad'
        async function test(){
             let getFristPoint = new MxCADUiPrPoint();
             let offsetDist = 10 ;
             let getent = new MxCADUiPrEntity();

Getent.setMessage ('specify offset object '); let ent_id = await getEnt.go(); if (!ent_id) return; let ent = (await ent_id.getMcDbEntity()) as McDbCurve; let getoOffPt = new MxCADUiPrPoint(); GetoOffPt.setMessage ('specify offset point '); let offPt = await getoOffPt.go(); if (!offPt) return; let objArr = ent.offsetCurves(offsetDist, offPt); if (objArr.length() === 0) return; objArr.forEach((obj: McDbObject) => { MxCpp.getCurrentCAD().drawEntity(obj as McDbEntity); }); } * ```

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McDbObjectArray(imp?)

Constructor.

Parameters

NameTypeDescription
imp?AnyInternal implementation object

Properties

aryVal

aryVal: McDbObject[] = []

object array

Methods

empty

empty(): boolean

Clear the array

Returns

boolean


forEach

forEach(call): void

Traverse objects

Parameters

NameType
call(val: McDbObject, index: number) => void

Returns

void


length

length(): number

Array length

Returns

number