[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:
- Create a selection set using new MxCADSelectionSet();
- Call methods such as allSelect()/pointSelect()/userSelect() to select;
- Use count(), item(), forEach(), getIds () to read or iterate the results;
- Continue to perform subsequent operations such as highlighting, deleting, and modifying properties on the selected object.
Example
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
↳
MxCADSelectionSet
Table of contents
Constructors
Properties
Accessors
Methods
- allSelect
- clear
- count
- crossingSelect
- currentSelect
- fenceSelect
- forEach
- getIds
- getImp
- getJson
- getSelectPoint
- getSelectPoints
- initTempObject
- isKindOf
- isNull
- item
- pointSelect
- setJson
- userSelect
Constructors
constructor
• new MxCADSelectionSet()
Constructor function
Overrides
Properties
imp
• imp: any = 0
Internal implementation object.
Inherited from
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
| Name | Type |
|---|---|
val | boolean |
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
| Name | Type | Default value | Description |
|---|---|---|---|
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
Returns
number
Example
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
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
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
| Name | Type | Default value | Description |
|---|---|---|---|
| DX1 | number | undefined | X-axis value of corner 1 |
| DY1 | number | undefined | Y-axis value of corner 1 |
| DX2 | number | undefined | X-axis value of corner 2 |
| DY2 | number | undefined | Y-axis value of corner 2 |
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
Returns
number
Entity Object Index
currentSelect
▸ currentSelect(filter?): number
Get the currently selected object
Parameters
| Name | Type | Default value |
|---|---|---|
filter | null | MxCADResbuf | null |
Returns
number
Select ID object array
fenceSelect
▸ fenceSelect(strPrompt?, filter?, init?): Promise<boolean>
Select objects on the map according to the fence method
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | undefined | Interactive prompt information, can be empty. |
filter | null \ | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
init? | (getPoint: MrxDBgUiPrPoint)=>any | undefined | The 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
| Name | Type |
|---|---|
call | (val: McObjectId) => void |
Returns
void
Example
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
Select ID object array
getImp
▸ getImp(): any
Retrieve internal implementation objects.
Returns
any
Internal implementation object.
Inherited from
getJson
▸ getJson(): string
Retrieve a string in JSON format.
Returns
string
A string in JSON format.
Inherited from
getSelectPoint
▸ getSelectPoint(): Object
Obtain the two diagonal points formed by the selection
Returns
Object
Pt1 corner point 1 | pt2 corner point 2
| Name | Type |
|---|---|
pt1 | McGePoint3d |
pt2 | McGePoint3d |
getSelectPoints
▸ getSelectPoints(): McGePoint3d[]
Return the selection point array.
Returns
Select box point array
initTempObject
▸ initTempObject(imp): void
Initialize temporary objects.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | Internal implementation object |
Returns
void
Inherited from
isKindOf
▸ isKindOf(sObjectName): boolean
Determine object type
Parameters
| Name | Type | Description |
|---|---|---|
| SOrtName | string | Type Name |
Returns
boolean
Return whether the object is of the target type
Inherited from
isNull
▸ isNull(): boolean
Determine if the selection set is empty
Returns
boolean
Boolean value
Overrides
item
▸ item(lItem): McObjectId
Obtain the corresponding object ID based on the object index
Parameters
| Name | Type | Description |
|---|---|---|
| List | Number | Object Index |
Returns
Object ID
Example
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
| Name | Type | Default value | Description |
|---|---|---|---|
| DX | number | undefined | coordinate x |
| DY | number | undefined | coordinate y |
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
dTol | number | -1 | - |
Returns
number
Entity Object Index
Example
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
| Name | Type | Description |
|---|---|---|
| Str | string | JSON formatted string |
Returns
boolean
Is the setting successful.
Inherited from
userSelect
▸ userSelect(strPrompt?, filter?, init?): Promise<boolean>
User selection
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | [Object]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object ) | undefined | String prompt |
| Filter | null | [MxCADResbuf] (2d. MxCADResbuf. md) | null |
init? | (getPoint: MrxDBgUiPrPoint)=>any | undefined | Initialization operation before user selection |
Returns
Promise<boolean>
Example
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);
}