Skip to content
On this page

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

Class: MxCADSelectionSet

2d.MxCADSelectionSet

Selection set is used to select entities

Example

ts
For example, filtering and selecting all PL line objects on the graph by extending the data name DataName
 let ss = new MxCADSelectionSet();
         ss.allSelect(new MxCADResbuf([DxfCode.kAppName,0,1001,"DataName",DxfCode.kEntityType, "LWPOLYLINE"]));
         ss.forEach(id=>{
             let ent = id.getMcDbEntity();
             if(ent){
                 console.log(ent.getxDataString("DataName") ); 
             }
         })

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new MxCADSelectionSet()

Constructor function

Example

ts
import { MxCADSelectionSet } from "mxcad";
  let ss = new MxCADSelectionSet();

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

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  ss.isSelectHighlight = true;

isWhileSelect

isWhileSelect: boolean = true

Is there a loop selection

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  ss.isWhileSelect = false;

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


objectName

get objectName(): string

Get the object name.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.objectName);

Returns

string

Return object name

Inherited from

McRxObject.objectName

Methods

allSelect

allSelect(filter?): number

Select All

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();   
 })

Parameters

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

Returns

number


count

count(): number

Get the current selected number

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
  const count = ss.count();
  console.log(count);

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

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  const index = ss.pointSelect(0,0,20,10);

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


forEach

forEach(call): void

Traverse the selected entities

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

Parameters

NameType
call(val: McObjectId) => void

Returns

void


getIds

getIds(): McObjectId[]

Obtain the IDs of all currently selected objects

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  ss.allSelect();
  const ids = ss.getIds();

Returns

McObjectId[]

Select ID object array


getImp

getImp(): any

Retrieve internal implementation objects.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let imp = obj.getImp();

Returns

any

Internal implementation object.

Inherited from

McRxObject.getImp


getJson

getJson(): string

Retrieve a string in JSON format.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const json = obj.getJson()

Returns

string

A string in JSON format.

Inherited from

McRxObject.getJson


getSelectPoint

getSelectPoint(): Object

Obtain the two diagonal points formed by the selection

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
  const selectPt  = ss.getSelectPoint();
  console.log(selectPt.pt1, selectPt.pt2);

Returns

Object

Pt1 corner point 1 | pt2 corner point 2

NameType
pt1McGePoint3d
pt2McGePoint3d

initTempObject

initTempObject(imp): void

Initialize temporary objects.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
obj.initTempObject()

Parameters

NameTypeDescription
'imp''any'Internal implementation object

Returns

void

Inherited from

McRxObject.initTempObject


isKindOf

isKindOf(sObjectName): boolean

Determine object type

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); //  Output: True or false

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

Example

ts
import { MxCADSelectionSet } from "mxcad";
 
  let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
  const res = ss.isNull();

Returns

boolean

Boolean value

Overrides

McRxObject.isNull


item

item(lItem): McObjectId

Obtain the corresponding object ID based on the object index

Example

ts
import { MxCADSelectionSet } from "mxcad";

  let ss = new MxCADSelectionSet();
  const objId = ss.item(2);

Parameters

NameTypeDescription
ListNumberObject Index

Returns

McObjectId

Object ID


pointSelect

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

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

Example

ts
import { MxCADSelectionSet } from "mxcad";
 
  let ss = new MxCADSelectionSet();
  const index = ss.pointSelect(20,10);

Parameters

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

Returns

number

Entity Object Index


setJson

setJson(str): boolean

Set a string in JSON format.

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)

Parameters

NameTypeDescription
StrstringJSON formatted string

Returns

boolean

Is the setting successful.

Inherited from

McRxObject.setJson


userSelect

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

User selection

Example

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

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

Parameters

NameTypeDefault valueDescription
strPrompt?` StringundefinedString prompt
Filternull[MxCADResbuf] (2d. MxCADResbuf. md)null
init?(getPoint: MrxDBgUiPrPoint)=>anyundefinedInitialization operation before user selection

Returns

Promise<boolean>