Table of Contents

Method FilterEntities

Namespace
vdWebLibrary
Assembly
JsPropertiesExtractor.dll

FilterEntities(object, vdFilterEntityDelegate)

Enumerate all the entities in the selected document and calls the passed function for each entity.

public object[] FilterEntities(object customdataObject, vdFilterEntityDelegate filterdelegate)

Parameters

customdataObject object

A user object that will be passed to the filterdelegate arguments. May be null.

filterdelegate vdFilterEntityDelegate

A user function of vdFilterEntityDelegate type that will be called for each entity.

Returns

object[]

An array of entities depends on the code that the user uses in the passed function.

Examples

Example 1: Select all entities in the Model layout that reference the Layer with name "MyLayer1".

var layHandle = 'h_' + vdcanvas.FindLayer("MyLayer1").HandleId.toString();
var selection = vdcanvas.FilterEntities(layHandle, function (args) {
if (args.owner != args.document.Model) {//filter owner of entity
args.cancel = true;//do not Enumerate entites that are not in the Model layout
return;
}
if (args.entity) {//filter entity
if (args.entity.Layer != args.customdata) //do not add the entities that their Layer is other than 'MyLayer1' Layer(NOTE: this layer handle is passed to the FilterEntities customdataObject parameter
args.cancel = true;
}
}//close the function delegate
);//close the FilterEntities function
//erase the selected entities( Entities that belong to Model layout and reference the layer with name 'MyLayer1'
vdcanvas.scriptCommand.select(selection, function (_vdcanvas) { _vdcanvas.scriptCommand.erase(); _vdcanvas.redraw(); });

Example 2: Select only the entities of the "newlayout" layout and pass the selection to the move() method.

var vddoc = vdcanvas.GetDocument();
var layoutID = vdcanvas.FindLayout("newlayout");
if (layoutID == -1) return;
else {
var layout = vddoc.LayOuts.Items[layoutID];
var selection = vdcanvas.FilterEntities(layout, function (args) {
if (args.owner != layout) {
args.cancel = true;
return;
}
             }
            );

             vdcanvas.scriptCommand.select(selection, function (_vdcanvas) { _vdcanvas.scriptCommand.move(); });
         }</code></pre>

Example 3: Select only the the vdInserts object with Block name == "myblock" of the Model and pass the selected vdInsert to the move() method.

var block = vdcanvas.FindBlock("myblock");
var blockHandle = "h_" + block.HandleId.toString();
var selection = vdcanvas.FilterEntities(blockHandle, function (args) {
if (args.owner != args.document.Model) {
args.cancel = true;
return;
}
if (args.entity) {//filter entity
if (args.entity._t != vdConst.vdInsert_code || args.entity.Block != args.customdata) {
args.cancel = true; } } } );
            vdcanvas.scriptCommand.select(selection, function (_vdcanvas) { _vdcanvas.scriptCommand.move(); });</code></pre>