Skip to content
On this page

mxcad_2d API 文档 / 2d / MxCADSelectionSet

Class: MxCADSelectionSet

2d.MxCADSelectionSet

选择集 用于选择实体

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new MxCADSelectionSet()

构造函数

Example

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

Overrides

McRxObject.constructor

Properties

imp

imp: any = 0

内部实现对象。

Inherited from

McRxObject.imp


isSelectHighlight

isSelectHighlight: boolean = true

选择是否高亮

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

isWhileSelect

isWhileSelect: boolean = true

是否循环选择

Example

ts
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

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.objectName

Methods

allSelect

allSelect(filter?): number

全选

Parameters

NameTypeDefault valueDescription
filternull | MxCADResbufnull过滤对象

Returns

number

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();
   // 得到图上,直线,圆,圆弧,多义线,在0层上的对象.
   ss.allSelect(new MxCADResbuf([DxfCode.kEntityType, "LINE,ARC,CIRCLE,LWPOLYLINE",DxfCode.kLayer,"0"]));
   console.log("得到对象数目:" + ss.count());

count

count(): number

获取当前选中的个数

Returns

number

当前选中实体个数

Example

ts
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

NameTypeDefault valueDescription
dX1numberundefined角点1 X轴值
dY1numberundefined角点1 Y轴值
dX2numberundefined角点2 X轴值
dY2numberundefined角点2 Y轴值
filternull | MxCADResbufnull过滤对象

Returns

number

实体对象索引

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

forEach

forEach(call): void

遍历已选中的实体

Parameters

NameType
call(val: McObjectId) => void

Returns

void

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

getIds

getIds(): McObjectId[]

得到当前已选中的所有对象ID

Returns

McObjectId[]

选中id对象数组

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

getImp

getImp(): any

获取内部实现对象。

Returns

any

内部实现对象。

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.getImp


getJson

getJson(): string

获取 JSON 格式的字符串。

Returns

string

JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.getJson


getSelectPoint

getSelectPoint(): Object

得到选择形成的两个对角点

Returns

Object

pt1 角点1 | pt2 角点2

NameType
pt1McGePoint3d
pt2McGePoint3d

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

initTempObject

initTempObject(imp): void

初始化临时对象。

Parameters

NameTypeDescription
impany内部实现对象。

Returns

void

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.initTempObject


isKindOf

isKindOf(sObjectName): boolean

判断对象类型

Parameters

NameTypeDescription
sObjectNamestring类型名

Returns

boolean

返回对象是否是目标类型

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false

Inherited from

McRxObject.isKindOf


isNull

isNull(): boolean

判断选择集是否为空

Returns

boolean

布尔值

Example

ts
import { MxCADSelectionSet } from "mxcad";
 
  let ss = new MxCADSelectionSet();
  if (!await ss.userSelect("选择目标范围")) return;
  const res = ss.isNull();

Overrides

McRxObject.isNull


item

item(lItem): McObjectId

根据对象索引 得到对应对象ID

Parameters

NameTypeDescription
lItemnumber对象索引

Returns

McObjectId

对象id

Example

ts
import { MxCADSelectionSet } from "mxcad";

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

pointSelect

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

根据一个坐标点选择一个实体对象的索引

Parameters

NameTypeDefault valueDescription
dXnumberundefined坐标x
dYnumberundefined坐标y
filternull | MxCADResbufnull过滤对象
dTolnumber-1-

Returns

number

实体对象索引

Example

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

setJson

setJson(str): boolean

设置 JSON 格式的字符串。

Parameters

NameTypeDescription
strstringJSON 格式的字符串。

Returns

boolean

是否设置成功。

Example

ts
import { McRxObject } from 'mxcad';

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

Inherited from

McRxObject.setJson


userSelect

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

用户选择

Parameters

NameTypeDefault valueDescription
strPrompt?stringundefined字符串提示
filternull | MxCADResbufnull提示
init?(getPoint: MrxDbgUiPrPoint) => anyundefined用户选择前的初始化操作

Returns

Promise<boolean>

Example

ts
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);