mxcad_2d API 文档 / 2d / MxCADSelectionSet
Class: MxCADSelectionSet
2d.MxCADSelectionSet
选择集 用于选择实体
Hierarchy
↳
MxCADSelectionSet
Table of contents
Constructors
Properties
Accessors
Methods
- allSelect
- count
- crossingSelect
- forEach
- getIds
- getImp
- getJson
- getSelectPoint
- initTempObject
- isKindOf
- isNull
- item
- pointSelect
- setJson
- userSelect
Constructors
constructor
• new MxCADSelectionSet()
构造函数
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
Overrides
Properties
imp
• imp: any
= 0
内部实现对象。
Inherited from
isSelectHighlight
• isSelectHighlight: boolean
= true
选择是否高亮
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.isSelectHighlight = true;
isWhileSelect
• isWhileSelect: boolean
= true
是否循环选择
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.isWhileSelect = false;
Accessors
dxf0
• get
dxf0(): string
得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。
Returns
string
Inherited from
McRxObject.dxf0
objectName
• get
objectName(): string
获取对象名称。
Returns
string
返回对象名
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Inherited from
McRxObject.objectName
Methods
allSelect
▸ allSelect(filter?
): number
全选
Parameters
Name | Type | Default value | Description |
---|---|---|---|
filter | null | MxCADResbuf | 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();
// 得到图上,直线,圆,圆弧,多义线,在0层上的对象.
ss.allSelect(new MxCADResbuf([DxfCode.kEntityType, "LINE,ARC,CIRCLE,LWPOLYLINE",DxfCode.kLayer,"0"]));
console.log("得到对象数目:" + ss.count());
count
▸ count(): number
获取当前选中的个数
Returns
number
当前选中实体个数
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
根据两个对角点选择一个实体对象的索引
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dX1 | number | undefined | 角点1 X轴值 |
dY1 | number | undefined | 角点1 Y轴值 |
dX2 | number | undefined | 角点2 X轴值 |
dY2 | number | undefined | 角点2 Y轴值 |
filter | null | MxCADResbuf | null | 过滤对象 |
Returns
number
实体对象索引
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(0,0,20,10);
forEach
▸ forEach(call
): void
遍历已选中的实体
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
[]
得到当前已选中的所有对象ID
Returns
选中id对象数组
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.allSelect();
const ids = ss.getIds();
getImp
▸ getImp(): any
获取内部实现对象。
Returns
any
内部实现对象。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Returns
string
JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Inherited from
getSelectPoint
▸ getSelectPoint(): Object
得到选择形成的两个对角点
Returns
Object
pt1 角点1 | pt2 角点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);
initTempObject
▸ initTempObject(imp
): void
初始化临时对象。
Parameters
Name | Type | Description |
---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Inherited from
isKindOf
▸ isKindOf(sObjectName
): boolean
判断对象类型
Parameters
Name | Type | Description |
---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false
Inherited from
isNull
▸ isNull(): boolean
判断选择集是否为空
Returns
boolean
布尔值
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
if (!await ss.userSelect("选择目标范围")) return;
const res = ss.isNull();
Overrides
item
▸ item(lItem
): McObjectId
根据对象索引 得到对应对象ID
Parameters
Name | Type | Description |
---|---|---|
lItem | number | 对象索引 |
Returns
对象id
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const objId = ss.item(2);
pointSelect
▸ pointSelect(dX
, dY
, filter?
, dTol?
): number
根据一个坐标点选择一个实体对象的索引
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dX | number | undefined | 坐标x |
dY | number | undefined | 坐标y |
filter | null | MxCADResbuf | null | 过滤对象 |
dTol | number | -1 | - |
Returns
number
实体对象索引
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(20,10);
setJson
▸ setJson(str
): boolean
设置 JSON 格式的字符串。
Parameters
Name | Type | Description |
---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
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
>
用户选择
Parameters
Name | Type | Default value | Description |
---|---|---|---|
strPrompt? | string | undefined | 字符串提示 |
filter | null | MxCADResbuf | null | 提示 |
init? | (getPoint : MrxDbgUiPrPoint ) => any | undefined | 用户选择前的初始化操作 |
Returns
Promise
<boolean
>
Example
import { MxCADResbuf, MxCADSelectionSet } from "mxcad";
let filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("INSERT");
let ss = new MxCADSelectionSet();
if (!await ss.userSelect("选择要刷的目标块:", filter)) return;
if (ss.count() == 0) return;
let ids = ss.getIds();
console.log(ids);