[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCADSelectionSet
Class: MxCADSelectionSet
2d.MxCADSelectionSet
Selection set is used to select entities
Example
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
↳
MxCADSelectionSet
Table of contents
Constructors
Properties
Accessors
Methods
- allSelect
- clear
- count
- crossingSelect
- fenceSelect
- forEach
- getIds
- getImp
- getJson
- getSelectPoint
- getSelectPoints
- initTempObject
- isKindOf
- isNull
- item
- pointSelect
- setJson
- userSelect
Constructors
constructor
• new MxCADSelectionSet()
constructor
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();Overrides
Properties
imp
• imp: any = 0
Internal implementation object.
Inherited from
isSelectHighlight
• isSelectHighlight: boolean = true
Choose whether to highlight or not
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.isSelectHighlight = true;isWhileSelect
• isWhileSelect: boolean = true
Is there a loop selection
Example
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 a line is McDbLine, and the DXF0 group code value is LINE. The DXF0 group code value can be used for type filtering when constructing sets.
Returns
string
Inherited from
McRxObject.dxf0
objectName
• get objectName(): string
Get the object name.
Returns
string
Return object name
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);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
Example
count
▸ count(): number
Get the current selected number
Returns
number
The current number of selected entities
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
const count = ss.count();
console.log(count);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
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(0,0,20,10);fenceSelect
▸ fenceSelect(strPrompt?, filter?, init?): Promise<boolean>
Parameters
| Name | Type | Default value |
|---|---|---|
strPrompt? | string | undefined |
filter | null | MxCADResbuf | null |
init? | (getPoint: MrxDbgUiPrPoint) => any | undefined |
Returns
Promise<boolean>
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
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.allSelect();
const ids = ss.getIds();getImp
▸ getImp(): any
Retrieve internal implementation objects.
Returns
any
Internal implementation object.
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();Inherited from
getJson
▸ getJson(): string
Retrieve a string in JSON format.
Returns
string
A string in JSON format.
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()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 |
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
const selectPt = ss.getSelectPoint();
console.log(selectPt.pt1, selectPt.pt2);getSelectPoints
▸ getSelectPoints(): McGePoint3d[]
Return the selection point array.
Returns
Example
initTempObject
▸ initTempObject(imp): void
Initialize temporary objects.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | Internal implementation object. |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()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
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); //Output: true or falseInherited from
isNull
▸ isNull(): boolean
Determine if the selection set is empty
Returns
boolean
Boolean value
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
If (! Await ss.userSelect) return;
const res = ss.isNull();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";
let ss = new MxCADSelectionSet();
const objId = ss.item(2);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 } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(20,10);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.
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)Inherited from
userSelect
▸ userSelect(strPrompt?, filter?, init?): Promise<boolean>
User selection
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strPrompt? | string | 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";
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);