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
获取对象名称。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Returns
string
返回对象名
Inherited from
McRxObject.objectName
Methods
allSelect
▸ allSelect(filter?
): 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());
Parameters
Name | Type | Default value | Description |
---|---|---|---|
filter | null | MxCADResbuf | null | 过滤对象 |
Returns
number
count
▸ count(): number
获取当前选中的个数
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
if (!await ss.userSelect("选择目标范围")) return;
const count = ss.count();
console.log(count);
Returns
number
当前选中实体个数
crossingSelect
▸ crossingSelect(dX1
, dY1
, dX2
, dY2
, filter?
): number
根据两个对角点选择一个实体对象的索引
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(0,0,20,10);
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
实体对象索引
forEach
▸ forEach(call
): void
遍历已选中的实体
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.allSelect();
ss.forEach((id) => {
let ent: any = id.getMcDbEntity();
})
Parameters
Name | Type |
---|---|
call | (val : McObjectId ) => void |
Returns
void
getIds
▸ getIds(): McObjectId
[]
得到当前已选中的所有对象ID
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
ss.allSelect();
const ids = ss.getIds();
Returns
选中id对象数组
getImp
▸ getImp(): any
获取内部实现对象。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Returns
any
内部实现对象。
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Returns
string
JSON 格式的字符串。
Inherited from
getSelectPoint
▸ getSelectPoint(): Object
得到选择形成的两个对角点
Example
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 角点1 | pt2 角点2
Name | Type |
---|---|
pt1 | McGePoint3d |
pt2 | McGePoint3d |
initTempObject
▸ initTempObject(imp
): void
初始化临时对象。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Parameters
Name | Type | Description |
---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Inherited from
isKindOf
▸ isKindOf(sObjectName
): boolean
判断对象类型
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false
Parameters
Name | Type | Description |
---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Inherited from
isNull
▸ isNull(): boolean
判断选择集是否为空
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
if (!await ss.userSelect("选择目标范围")) return;
const res = ss.isNull();
Returns
boolean
布尔值
Overrides
item
▸ item(lItem
): McObjectId
根据对象索引 得到对应对象ID
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const objId = ss.item(2);
Parameters
Name | Type | Description |
---|---|---|
lItem | number | 对象索引 |
Returns
对象id
pointSelect
▸ pointSelect(dX
, dY
, filter?
, dTol?
): number
根据一个坐标点选择一个实体对象的索引
Example
import { MxCADSelectionSet } from "mxcad";
let ss = new MxCADSelectionSet();
const index = ss.pointSelect(20,10);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dX | number | undefined | 坐标x |
dY | number | undefined | 坐标y |
filter | null | MxCADResbuf | null | 过滤对象 |
dTol | number | -1 | - |
Returns
number
实体对象索引
setJson
▸ setJson(str
): boolean
设置 JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)
Parameters
Name | Type | Description |
---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
Inherited from
userSelect
▸ userSelect(strPrompt?
, filter?
, init?
): 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);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
strPrompt? | string | undefined | 字符串提示 |
filter | null | MxCADResbuf | null | 提示 |
init? | (getPoint : MrxDbgUiPrPoint ) => any | undefined | 用户选择前的初始化操作 |
Returns
Promise
<boolean
>