[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:
- First, create the McDDbPatchalFilter object.
- Reconfigure its boundary point set and enable status.
- Finally, use it to query or filter entity objects that meet spatial conditions.
Example
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
↳
McDbSpatialFilter
Table of contents
Constructors
Properties
Accessors
Methods
- assertObjectModification
- boundary
- clone
- createExtensionDictionary
- erase
- getDatabase
- getDatabaseIndexId
- getExtensionDictionary
- getGripEditBasePointsIndex
- getGripPoints
- getHandle
- getImp
- getJson
- getObjectID
- getOwnerID
- initTempObject
- isEnabled
- isErased
- isFilterInverted
- isHaveExtensionDictionary
- isKindOf
- isNull
- moveGripPointsAt
- setBoundary
- setEnable
- setFilterInverted
- setJson
- unErase
Constructors
constructor
• new McDbSpatialFilter(imp?)
Initialize a new instance of McDDbPatchalFilter.
Parameters
| Name | Type |
|---|---|
imp? | any |
Overrides
Properties
imp
• imp: any = 0
Internal implementation object.
Inherited from
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
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoUndo | boolean | false | Should 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
clone
▸ clone(): null | McDbObject
Clone objects.
Returns
null | McDbObject
The cloned object.
Inherited from
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
getDatabase
▸ getDatabase(): McDbDatabase
Get the database where the object is located
Returns
Return to database
Inherited from
getDatabaseIndexId
▸ getDatabaseIndexId(): number
Get the index ID of the object
Returns
number
Inherited from
getExtensionDictionary
▸ getExtensionDictionary(): McDbDictionary
Obtain the extended dictionary data of the object
Returns
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
Inherited from
getHandle
▸ getHandle(): string
Obtain object handle
Returns
string
Return object handle
Inherited from
getImp
▸ getImp(): any
Retrieve internal implementation objects.
Returns
any
Internal implementation object.
Inherited from
getJson
▸ getJson(): string
Retrieve a string in JSON format.
Returns
string
A string in JSON format.
Inherited from
getObjectID
▸ getObjectID(): McObjectId
Get the object ID.
Returns
Object ID.
Inherited from
getOwnerID
▸ getOwnerID(): number
Obtain the ID of the object owner
Returns
number
Inherited from
initTempObject
▸ initTempObject(imp): void
Initialize temporary objects.
Parameters
| Name | Type | Description |
|---|---|---|
| 'imp' | 'any' | Internal implementation object |
Returns
void
Inherited from
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
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
| Name | Type | Description |
|---|---|---|
| SOrtName | string | Type Name |
Returns
boolean
Return whether the object is of the target type
Inherited from
isNull
▸ isNull(): any
Determine if it is an empty object
Returns
any
Inherited from
moveGripPointsAt
▸ moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any
Grips for moving objects
Parameters
| Name | Type | Description |
|---|---|---|
| IIndex | Number | Index |
| DXOffset | number | X-axis offset |
| DYOffset | number | Y-axis offset |
| DZOffset | number | Z-axis offset |
Returns
any
Inherited from
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
| Name | Type |
|---|---|
aryPoint | McGePoint3dArray |
Returns
boolean
boolean
setEnable
▸ setEnable(val): boolean
Set whether to enable cutting boundaries
Parameters
| Name | Type |
|---|---|
val | boolean |
Returns
boolean
boolean
setFilterInverted
▸ setFilterInverted(val): boolean
Set the cutting boundary in reverse
Parameters
| Name | Type |
|---|---|
val | boolean |
Returns
boolean
boolean
setJson
▸ setJson(str): boolean
Set a string in JSON format.
Parameters
| Name | Type | Description |
|---|---|---|
| Str | string | JSON formatted string |
Returns
boolean
Is the setting successful.
Inherited from
unErase
▸ unErase(): boolean
Anti delete object.
Returns
boolean
