Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McDDbPatchalFilter

Class: McDbSpatialFilter ​

2d.McDbSpatialFilter

McDDbSpatialFilter is a spatial filter class used to filter objects by spatial range.

Description

This class is used to construct spatial filtering conditions and perform range filtering on object collections.

Summary of usage:

  1. First, create the McDDbPatchalFilter object.
  2. Reconfigure its boundary point set and enable status.
  3. Finally, use it to query or filter entity objects that meet spatial conditions.

Example

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

//Create edge clipping blocks
   async function MxTest_SelectEntitysToSpatialFilterBlock() {
       let ss = new MxCADSelectionSet();
If (! Await ss.userSelect ("Select the object to be made into a block:") 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;
//Set the insertion base point of the block at the center position of the graphic object.
       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;

//Set a circle as its cutting boundary
       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?)

Initialize a new instance of McDDbPatchalFilter.

Parameters ​

NameType
imp?any

Overrides ​

McDbObject.constructor

Properties ​

imp ​

• imp: any = 0

Internal implementation object.

Inherited from ​

McDbObject.imp

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 the line is McDbLine, and the group code value for DXF0 is: LINE and DXF0 group code values can be used for type filtering when constructing sets.

Returns ​

string

Inherited from ​

McDbObject.dxf0


objectName ​

• get objectName(): string

Get the object name.

Returns ​

string

Return object name

Inherited from ​

McDbObject.objectName

Methods ​

assertObjectModification ​

▸ assertObjectModification(autoUndo?): number

Setting the state of the object to be changed can automatically trigger the update display function to update the display. For example, if the block table record is updated and the block reference needs to be notified to update the display, this function can be called.

Parameters ​

NameTypeDefault valueDescription
AutoUndobooleanfalseShould this modification automatically support undo? Default is false

Returns ​

number

Inherited from ​

McDbObject.assertObjectModification


boundary ​

▸ boundary(): McGePoint3dArray

Return the cut boundary array points

Returns ​

McGePoint3dArray

McGePoint3dArray


clone ​

▸ clone(): null | McDbObject

Clone objects.

Returns ​

null | McDbObject

The cloned object.

Inherited from ​

McDbObject.clone


createExtensionDictionary ​

▸ createExtensionDictionary(): boolean

Create extended dictionary data for objects

Returns ​

boolean

Inherited from ​

McDbObject.createExtensionDictionary


erase ​

▸ erase(): boolean

Delete object.

Returns ​

boolean

Whether the deletion was successful.

Inherited from ​

McDbObject.erase


getDatabase ​

▸ getDatabase(): McDbDatabase

Get the database where the object is located

Returns ​

McDbDatabase

Return to database

Inherited from ​

McDbObject.getDatabase


getDatabaseIndexId ​

▸ getDatabaseIndexId(): number

Get the index ID of the object

Returns ​

number

Inherited from ​

McDbObject.getDatabaseIndexId


getExtensionDictionary ​

▸ getExtensionDictionary(): McDbDictionary

Obtain the extended dictionary data of the object

Returns ​

McDbDictionary

Expand dictionary data

Inherited from ​

McDbObject.getExtensionDictionary


getGripEditBasePointsIndex ​

▸ getGripEditBasePointsIndex(): number[]

Retrieve the edit base point index corresponding to the grip of the object.

Returns ​

number[]

Inherited from ​

McDbObject.getGripEditBasePointsIndex


getGripPoints ​

▸ getGripPoints(): McGePoint3dArray

Get the grip array of the object

Returns ​

McGePoint3dArray

Inherited from ​

McDbObject.getGripPoints


getHandle ​

▸ getHandle(): string

Obtain object handle

Returns ​

string

Return object handle

Inherited from ​

McDbObject.getHandle


getImp ​

▸ getImp(): any

Retrieve internal implementation objects.

Returns ​

any

Internal implementation object.

Inherited from ​

McDbObject.getImp


getJson ​

▸ getJson(): string

Retrieve a string in JSON format.

Returns ​

string

A string in JSON format.

Inherited from ​

McDbObject.getJson


getObjectID ​

▸ getObjectID(): McObjectId

Get the object ID.

Returns ​

McObjectId

Object ID.

Inherited from ​

McDbObject.getObjectID


getOwnerID ​

▸ getOwnerID(): number

Obtain the ID of the object owner

Returns ​

number

Inherited from ​

McDbObject.getOwnerID


initTempObject ​

▸ initTempObject(imp): void

Initialize temporary objects.

Parameters ​

NameTypeDescription
'imp''any'Internal implementation object

Returns ​

void

Inherited from ​

McDbObject.initTempObject


isEnabled ​

▸ isEnabled(): boolean

Do you want to enable cutting boundaries

Returns ​

boolean

boolean


isErased ​

▸ isErased(): boolean

Has the object been deleted

Returns ​

boolean

Inherited from ​

McDbObject.isErased


isFilterInverted ​

▸ isFilterInverted(): boolean

Is the cutting boundary reversed

Returns ​

boolean

boolean


isHaveExtensionDictionary ​

▸ isHaveExtensionDictionary(): boolean

Is there any extended dictionary data available

Returns ​

boolean

Inherited from ​

McDbObject.isHaveExtensionDictionary


isKindOf ​

▸ isKindOf(sObjectName): boolean

Determine object type

Parameters ​

NameTypeDescription
SOrtNamestringType Name

Returns ​

boolean

Return whether the object is of the target type

Inherited from ​

McDbObject.isKindOf


isNull ​

▸ isNull(): any

Determine if it is an empty object

Returns ​

any

Inherited from ​

McDbObject.isNull


moveGripPointsAt ​

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

Grips for moving objects

Parameters ​

NameTypeDescription
IIndexNumberIndex
DXOffsetnumberX-axis offset
DYOffsetnumberY-axis offset
DZOffsetnumberZ-axis offset

Returns ​

any

Inherited from ​

McDbObject.moveGripPointsAt


setBoundary ​

▸ setBoundary(aryPoint): boolean

Set the cutting boundary array points, where the point coordinates are the coordinates in the block table record referenced by the block.

Parameters ​

NameType
aryPointMcGePoint3dArray

Returns ​

boolean

boolean


setEnable ​

▸ setEnable(val): boolean

Set whether to enable cutting boundaries

Parameters ​

NameType
valboolean

Returns ​

boolean

boolean


setFilterInverted ​

▸ setFilterInverted(val): boolean

Set the cutting boundary in reverse

Parameters ​

NameType
valboolean

Returns ​

boolean

boolean


setJson ​

▸ setJson(str): boolean

Set a string in JSON format.

Parameters ​

NameTypeDescription
StrstringJSON formatted string

Returns ​

boolean

Is the setting successful.

Inherited from ​

McDbObject.setJson


unErase ​

▸ unErase(): boolean

Anti delete object.

Returns ​

boolean

Inherited from ​

McDbObject.unErase