Skip to content

mxcad_2d API 文档 / 2d / McDbSpatialFilter

Class: McDbSpatialFilter ​

2d.McDbSpatialFilter

McDbSpatialFilter 是空间过滤器类,用于按空间范围筛选对象。

Description

该类用于构造空间筛选条件,对对象集合进行范围过滤。

使用方法总结:

  1. 先创建 McDbSpatialFilter 对象。
  2. 再配置其边界点集和启用状态。
  3. 最后将其用于查询或筛选满足空间条件的实体对象。

Example

ts
   import { MxCADSelectionSet, MxCpp, McDbBlockTableRecord, McDbEntity, McGePoint3d, McDbBlockReference, McDbCircle, McGePoint3dArray, McDbSpatialFilter } from "mxcad";

   // 创建边缘裁剪块
   async function MxTest_SelectEntitysToSpatialFilterBlock() {
       let ss = new MxCADSelectionSet();
       if (!await ss.userSelect("选择要做成块的对象:")) return;
       if (ss.count() == 0) return;

       let mxcad = MxCpp.getCurrentMxCAD();
       let blkTable = mxcad.getDatabase().getBlockTable();
       let blkRec = new McDbBlockTableRecord();
       let blkRecId = blkTable.add(blkRec);
       let blkTableRecord: McDbBlockTableRecord = blkRecId.getMcDbBlockTableRecord() as any;
       if (blkTableRecord == null) return;

       let pt1x: any, pt1y: any, pt2x: any, pt2y: any;
       ss.forEach((id) => {
           let ent = id.getMcDbEntity();
           if (!ent) return;

           let cent = ent.clone() as McDbEntity;
           blkTableRecord.appendAcDbEntity(cent);

           let entBox = ent.getBoundingBox();
           if (entBox.ret) {
               if (!pt1x) {
                   pt1x = entBox.minPt.x;
                   pt1y = entBox.minPt.y;
                   pt2x = entBox.maxPt.x;
                   pt2y = entBox.maxPt.y;
               }
               else {
                   if (pt1x > entBox.minPt.x) pt1x = entBox.minPt.x;
                   if (pt1y > entBox.minPt.y) pt1y = entBox.minPt.y;
                   if (pt2x < entBox.maxPt.x) pt2x = entBox.maxPt.x;
                   if (pt2y < entBox.maxPt.y) pt2y = entBox.maxPt.y;
               }
           }
       })
       if (pt1x === undefined) {
           return;
       }
       let insertPtx = pt1x + (pt2x - pt1x) * 0.5;
       let insertPty = pt1y + (pt2y - pt1y) * 0.5;
       // 设置图块的插入基点,在图形对象的中心位置。
       blkTableRecord.origin = new McGePoint3d(insertPtx, insertPty, 0);

       let blkRef = new McDbBlockReference();
       blkRef.blockTableRecordId = blkRecId;
       blkRef.position = new McGePoint3d(insertPtx + (pt2x - pt1x) * 3, insertPty + (pt2y - pt1y) * 3, 0);

       blkRef = mxcad.drawEntity(blkRef).getMcDbEntity() as McDbBlockReference;

       // 设置一个圆做它的剪切边界.
       let dR = (pt2x - pt1x);
       if (dR < (pt2y - pt1y)) dR = (pt2y - pt1y);
       dR *= 0.3;
       let circle = new McDbCircle(insertPtx, insertPty, 0, dR);
       let samplePoints = circle.getSamplePoints(dR * 0.00001);
       let aryPoint = new McGePoint3dArray();
       samplePoints.forEach((val, _type, dxf) => {
           if (dxf === 1010) {
               const point = new McGePoint3d(val.x, val.y, val.z)
               aryPoint.append(point);
           }
       });

       blkRef.createSpatialFilter();
       blkRef.scaleFactors = new McGePoint3d(3, 3, 3);
       let idSpatialFilter = blkRef.getSpatialFilterId();
       let blkFilter: McDbSpatialFilter = idSpatialFilter.getMcDbObject() as any;
       blkFilter.setBoundary(aryPoint);
       circle.center = blkRef.position;
       circle.radius = circle.radius * 3;
       mxcad.drawEntity(circle);
   };

Hierarchy ​

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McDbSpatialFilter(imp?)

初始化一个新的 McDbSpatialFilter 实例。

Parameters ​

NameType
imp?any

Overrides ​

McDbObject.constructor

Properties ​

imp ​

• imp: any = 0

内部实现对象。

Inherited from ​

McDbObject.imp

Accessors ​

dxf0 ​

• get dxf0(): string

得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。

Returns ​

string

Inherited from ​

McDbObject.dxf0


objectName ​

• get objectName(): string

获取对象名称。

Returns ​

string

返回对象名

Inherited from ​

McDbObject.objectName

Methods ​

assertObjectModification ​

▸ assertObjectModification(autoUndo?): number

设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。

Parameters ​

NameTypeDefault valueDescription
autoUndobooleanfalse这次修改是否要自动支持撤销,默认为false

Returns ​

number

Inherited from ​

McDbObject.assertObjectModification


boundary ​

▸ boundary(): McGePoint3dArray

返回剪切边界数组点.

Returns ​

McGePoint3dArray

McGePoint3dArray


clone ​

▸ clone(): null | McDbObject

克隆对象。

Returns ​

null | McDbObject

克隆出的对象。

Inherited from ​

McDbObject.clone


createExtensionDictionary ​

▸ createExtensionDictionary(): boolean

创建对象的扩展字典数据.

Returns ​

boolean

Inherited from ​

McDbObject.createExtensionDictionary


erase ​

▸ erase(): boolean

删除对象。

Returns ​

boolean

是否删除成功。

Inherited from ​

McDbObject.erase


getDatabase ​

▸ getDatabase(): McDbDatabase

得到对象所在的数据库

Returns ​

McDbDatabase

返回数据库

Inherited from ​

McDbObject.getDatabase


getDatabaseIndexId ​

▸ getDatabaseIndexId(): number

获取对象的索引ID

Returns ​

number

Inherited from ​

McDbObject.getDatabaseIndexId


getExtensionDictionary ​

▸ getExtensionDictionary(): McDbDictionary

得到对象的扩展字典数据.

Returns ​

McDbDictionary

扩展字典数据

Inherited from ​

McDbObject.getExtensionDictionary


getGripEditBasePointsIndex ​

▸ getGripEditBasePointsIndex(): number[]

获取对象的夹点对应的编辑基点索引。

Returns ​

number[]

Inherited from ​

McDbObject.getGripEditBasePointsIndex


getGripPoints ​

▸ getGripPoints(): McGePoint3dArray

获取对象的夹点数组

Returns ​

McGePoint3dArray

Inherited from ​

McDbObject.getGripPoints


getHandle ​

▸ getHandle(): string

得到对象句柄

Returns ​

string

返回对象句柄

Inherited from ​

McDbObject.getHandle


getImp ​

▸ getImp(): any

获取内部实现对象。

Returns ​

any

内部实现对象。

Inherited from ​

McDbObject.getImp


getJson ​

▸ getJson(): string

获取 JSON 格式的字符串。

Returns ​

string

JSON 格式的字符串。

Inherited from ​

McDbObject.getJson


getObjectID ​

▸ getObjectID(): McObjectId

获取对象 ID。

Returns ​

McObjectId

对象 ID。

Inherited from ​

McDbObject.getObjectID


getOwnerID ​

▸ getOwnerID(): number

得到对象拥用者的id

Returns ​

number

Inherited from ​

McDbObject.getOwnerID


initTempObject ​

▸ initTempObject(imp): void

初始化临时对象。

Parameters ​

NameTypeDescription
impany内部实现对象。

Returns ​

void

Inherited from ​

McDbObject.initTempObject


isEnabled ​

▸ isEnabled(): boolean

是否启用剪切边界

Returns ​

boolean

boolean


isErased ​

▸ isErased(): boolean

对象是否已经删除

Returns ​

boolean

Inherited from ​

McDbObject.isErased


isFilterInverted ​

▸ isFilterInverted(): boolean

剪切边界是否反向

Returns ​

boolean

boolean


isHaveExtensionDictionary ​

▸ isHaveExtensionDictionary(): boolean

是否有扩展字典数据.

Returns ​

boolean

Inherited from ​

McDbObject.isHaveExtensionDictionary


isKindOf ​

▸ isKindOf(sObjectName): boolean

判断对象类型

Parameters ​

NameTypeDescription
sObjectNamestring类型名

Returns ​

boolean

返回对象是否是目标类型

Inherited from ​

McDbObject.isKindOf


isNull ​

▸ isNull(): any

判断是否为空对象

Returns ​

any

Inherited from ​

McDbObject.isNull


moveGripPointsAt ​

▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any

移动对象的夹点

Parameters ​

NameTypeDescription
iIndexnumber索引
dXOffsetnumberX轴偏移量
dYOffsetnumberY轴偏移量
dZOffsetnumberZ轴偏移量

Returns ​

any

Inherited from ​

McDbObject.moveGripPointsAt


setBoundary ​

▸ setBoundary(aryPoint): boolean

设置剪切边界数组点,点坐标是块引用的块表记录中的坐标。

Parameters ​

NameType
aryPointMcGePoint3dArray

Returns ​

boolean

boolean


setEnable ​

▸ setEnable(val): boolean

设置是否启用剪切边界

Parameters ​

NameType
valboolean

Returns ​

boolean

boolean


setFilterInverted ​

▸ setFilterInverted(val): boolean

设置剪切边界反向

Parameters ​

NameType
valboolean

Returns ​

boolean

boolean


setJson ​

▸ setJson(str): boolean

设置 JSON 格式的字符串。

Parameters ​

NameTypeDescription
strstringJSON 格式的字符串。

Returns ​

boolean

是否设置成功。

Inherited from ​

McDbObject.setJson


unErase ​

▸ unErase(): boolean

反删除对象。

Returns ​

boolean

Inherited from ​

McDbObject.unErase