Skip to content

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

Class: MxCADSelectionSet ​

2d.MxCADSelectionSet

MxCADSelectionSet is a collection class used to manage and traverse objects in the current selection set.

Description

This class is used for object selection, filtering, traversal, and batch processing, and is suitable for "selected object queries" and "batch operations" in CAD graphic editing scenes. It can perform all selection, click selection, box selection, user interaction selection, and obtain the object ID in the selection set, and then call getMcDbEntity () to obtain the entity instance. Usage:

  1. Create a selection set using new MxCADSelectionSet();
  2. Call methods such as allSelect()/pointSelect()/userSelect() to select;
  3. Use count(), item(), forEach(), getIds () to read or iterate the results;
  4. Continue to perform subsequent operations such as highlighting, deleting, and modifying properties on the selected object.

Example

ts
import { MxCADResbuf, MxCADSelectionSet } from "mxcad";

const ss = new MxCADSelectionSet();
const filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("LINE,CIRCLE");

ss.allSelect(filter);
Console.log ("Number of selected objects:", ss. count());

ss.forEach((id) => {
  const ent = id.getMcDbEntity();
If (ent) console. log ("Entity:", ent. objectName);
});

Hierarchy ​

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new MxCADSelectionSet()

Constructor function

Overrides ​

McRxObject.constructor

Properties ​

imp ​

• imp: any = 0

Internal implementation object.

Inherited from ​

McRxObject.imp


isSelectHighlight ​

• isSelectHighlight: boolean = true

Choose whether to highlight or not


isWhileSelect ​

• isWhileSelect: boolean = true

Is there a loop selection

Accessors ​

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


isFilterLockLayer ​

• get isFilterLockLayer(): boolean

It filters out locked layers

Returns ​

boolean

• set isFilterLockLayer(val): void

Parameters ​

NameType
valboolean

Returns ​

void


objectName ​

• get objectName(): string

Get the object name.

Returns ​

string

Return object name

Inherited from ​

McRxObject.objectName

Methods ​

allSelect ​

▸ allSelect(filter?): number

Select All

Parameters ​

NameTypeDefault valueDescription
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null

Returns ​

number

Example

ts
  import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  ss.allSelect();
  ss.forEach((id) => {
       let ent: any = id.getMcDbEntity();
       if (!ent) return;
       ent = McDbEntityToJsonObject(ent);
       console.log(JSON.stringify(ent));
   })

Example

ts
   import { MxCADSelectionSet } from "mxcad";
   let ss = new MxCADSelectionSet();
//Obtain objects on the graph, including straight lines, circles, arcs, polylines, and at level 0
   ss.allSelect(new MxCADResbuf([DxfCode.kEntityType, "LINE,ARC,CIRCLE,LWPOLYLINE",DxfCode.kLayer,"0"]));
Console.log ("Get number of objects: " + ss.count());

Example

ts
   import { MxCADSelectionSet } from "mxcad";
   let ss = new MxCADSelectionSet();
//Obtain objects on layer 0
   ss.allSelect(new MxCADResbuf([DxfCode.kLayer,"0"]));
Console.log ("Get number of objects: " + ss.count());
//Traverse objects
    ss.forEach((id) => {
   let ent = id.getMcDbEntity();
   if (!ent) return;  
   let entBox = ent.getBoundingBox();   
 })

clear ​

▸ clear(): void

Clear selection set

Returns ​

void


count ​

▸ count(): number

Get the current selected number

Returns ​

number

The current number of selected entities


crossingSelect ​

▸ crossingSelect(dX1, dY1, dX2, dY2, filter?): number

Select an index for an entity object based on two diagonal points

Parameters ​

NameTypeDefault valueDescription
DX1numberundefinedX-axis value of corner 1
DY1numberundefinedY-axis value of corner 1
DX2numberundefinedX-axis value of corner 2
DY2numberundefinedY-axis value of corner 2
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null

Returns ​

number

Entity Object Index


currentSelect ​

▸ currentSelect(filter?): number

Get the currently selected object

Parameters ​

NameTypeDefault value
filternull | MxCADResbufnull

Returns ​

number

Select ID object array


fenceSelect ​

▸ fenceSelect(strPrompt?, filter?, init?): Promise<boolean>

Select objects on the map according to the fence method

Parameters ​

NameTypeDefault valueDescription
strPrompt? stringundefinedInteractive prompt information, can be empty.
filternull \[MxCADResbuf] (2d. MxCADResbuf. md)null
init? (getPoint: MrxDBgUiPrPoint)=>anyundefinedThe initialization callback before user selection, where prompt messages and interaction parameters can be set.

Returns ​

Promise<boolean>

Return a Promise that returns true when the user completes the fence selection and confirms, and false when canceling or exiting.


forEach ​

▸ forEach(call): void

Traverse the selected entities

Parameters ​

NameType
call(val: McObjectId) => void

Returns ​

void

Example

ts
  import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  ss.allSelect();
  ss.forEach((id) => {
      let ent: any = id.getMcDbEntity();
  })

getIds ​

▸ getIds(): McObjectId[]

Obtain the IDs of all currently selected objects

Returns ​

McObjectId[]

Select ID object array


getImp ​

▸ getImp(): any

Retrieve internal implementation objects.

Returns ​

any

Internal implementation object.

Inherited from ​

McRxObject.getImp


getJson ​

▸ getJson(): string

Retrieve a string in JSON format.

Returns ​

string

A string in JSON format.

Inherited from ​

McRxObject.getJson


getSelectPoint ​

▸ getSelectPoint(): Object

Obtain the two diagonal points formed by the selection

Returns ​

Object

Pt1 corner point 1 | pt2 corner point 2

NameType
pt1McGePoint3d
pt2McGePoint3d

getSelectPoints ​

▸ getSelectPoints(): McGePoint3d[]

Return the selection point array.

Returns ​

McGePoint3d[]

Select box point array


initTempObject ​

▸ initTempObject(imp): void

Initialize temporary objects.

Parameters ​

NameTypeDescription
'imp''any'Internal implementation object

Returns ​

void

Inherited from ​

McRxObject.initTempObject


isKindOf ​

▸ isKindOf(sObjectName): boolean

Determine object type

Parameters ​

NameTypeDescription
SOrtNamestringType Name

Returns ​

boolean

Return whether the object is of the target type

Inherited from ​

McRxObject.isKindOf


isNull ​

▸ isNull(): boolean

Determine if the selection set is empty

Returns ​

boolean

Boolean value

Overrides ​

McRxObject.isNull


item ​

▸ item(lItem): McObjectId

Obtain the corresponding object ID based on the object index

Parameters ​

NameTypeDescription
ListNumberObject Index

Returns ​

McObjectId

Object ID

Example

ts
 import { MxCADSelectionSet } from "mxcad";
//Select all proxy entities on the drawing
   async function TestGetProx() {
       let ss = new MxCADSelectionSet();
       let filter = new MxCADResbuf();
       filter.AddString("ACAD_PROXY_ENTITY", 5020)
       ss.allSelect(filter);
       let iCount = ss.count();
       for (let i = 0; i < iCount; i++) {
           let ent = ss.item(i).getMcDbEntity();
           if (!ent) continue;
           console.log(ent);
       }
  }

pointSelect ​

▸ pointSelect(dX, dY, filter?, dTol?): number

Select an index for a physical object based on a coordinate point

Parameters ​

NameTypeDefault valueDescription
DXnumberundefinedcoordinate x
DYnumberundefinedcoordinate y
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null
dTolnumber-1-

Returns ​

number

Entity Object Index

Example

ts
   import { MxCADSelectionSet, MxCADResbuf } from "mxcad"

//Select through a single point
   const ss = new MxCADSelectionSet();
   const filter = new MxCADResbuf();
//Add object types, select only text type objects in the selection set
   filter.AddMcDbEntityTypes("TEXT,MTEXT")
   const getPoint = new MxCADUiPrPoint()
   const point = await getPoint.go()
   if (!point) return;
//Add a filter to filter the selection set, where only text objects will be selected
   const index = ss.pointSelect(point.x, point.y, filter)
   const objId = ss.item(index)
   const ent = objId.getMcDbEntity()
   console.log(ent)

setJson ​

▸ setJson(str): boolean

Set a string in JSON format.

Parameters ​

NameTypeDescription
StrstringJSON formatted string

Returns ​

boolean

Is the setting successful.

Inherited from ​

McRxObject.setJson


userSelect ​

▸ userSelect(strPrompt?, filter?, init?): Promise<boolean>

User selection

Parameters ​

NameTypeDefault valueDescription
strPrompt? string | [Object]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object )undefinedString prompt
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null
init?(getPoint: MrxDBgUiPrPoint)=>anyundefinedInitialization operation before user selection

Returns ​

Promise<boolean>

Example

ts
  import { MxCADResbuf, MxCADSelectionSet } from "mxcad";

  function test(){
   let filter = new MxCADResbuf();
   filter.AddMcDbEntityTypes("INSERT");
   let ss = new MxCADSelectionSet();
If (! Await ss.userSelect ("select target block to be flashed:", filter)) return;
   if (ss.count() == 0) return;
   let ids = ss.getIds();
   console.log(ids);
  }