Fetching model elements
To fetch model elements, do the following:
On the Model Elements page, on the Fetch pane, from the ElementCategory dropdown, select an element category.
In the ElementType dropdown, select an element type.
Click FETCH.
The elements that have your category and type selection now appear in the Group and Filter pane and the Model Elements pane.
Optional: To group elements, in the Group and Filter pane, from the Group By dropdown, select a grouping.
Optional: To filter elements, in the Group and Filter pane, from the Filter By dropdown, select a filter.
To tag fetched elements with color tags, see Color tagging elements.
For more information on a model element's related data, see Related items.
Figure: Browsing model elements on the App page

Fetching entities using userConfig scripts#
The user can use the ElementCategory and ElementType dropdowns to filter project elements by their category and type, then fetch items that match the category and type. These items and their related items are mapped together as entities. These steps use the following scripts, which are located in iaf_dt_model_elems.js and configured in a userConfig:
getModelElementCategory: Gets all categoriesgetModelElementType: Gets all types for the selected categorygetModelElements: Fetches model elements for the selected category and type, then gets the properties and type information related to them to construct what we can call 'entities'.
Data loads in the ElementCategory and ElementType dropdowns#
The ElementType and ElementCategory dropdowns, are configured in the user config and are handled and rendered by ipaCore.
"entityDataConfig": { "Model Element": { "Element Properties": { "selected": true, "isProperties": true, "component": { "name": "SimpleTableGroup", //the ipaCore component to use "className": "simple-property-grid", "groupClassName": "simple-table-group-name", "groups": { "Base Properties": [ "ElementCategory", "ElementType" ] } } }, }}The display text and script to use for each dropdown is configured in entitySelectConfig.Model Element.selects:
"entitySelectConfig": { "Model Element": [ { "id": "revfam", "query": "<<SCRIPTED_LINKED_SELECTS>>", "display": "ElementCategory", "altScript": "getModelElementsByTypeProps", "selects": [ { "display": "ElementCategory", //display text "script": "getModelElementCategory", //script that gets the model element categories "propName": "ElementCategory" }, { "display": "ElementType", //display text "script": "getModelElementType", //script that gets the model element types "multi": true, //allows the selection of multiple values "propName": "ElementType" } ] } ],...}
The getModelElementCategory function gets the model's element category collection and returns the distinct element categories:
async getModelElementCategory(input, libraries, ctx, callback) { const { PlatformApi } = libraries; let iaf_ext_current_bim_model = PlatformApi.IafScriptEngine.getVar( "iaf_ext_current_bim_model" ); let type_elements_coll = await PlatformApi.IafScriptEngine.getCollectionInComposite( iaf_ext_current_bim_model._userItemId, { _userType: "rvt_type_elements", }, ctx ); console.log("type_elements_coll", type_elements_coll); let distinctCategories = await PlatformApi.IafScriptEngine.getDistinct( { collectionDesc: { _userType: type_elements_coll._userType, _userItemId: type_elements_coll._userItemId, }, field: "ElementCategory", query: {}, }, ctx ); console.log("distinctCategories", distinctCategories); distinctCategories = _.sortBy(distinctCategories, (type) => type); return distinctCategories; },
The getModelElementType function gets the model's element types collection and returns the distinct element types:
async getModelElementType(input, libraries, ctx, callback) { console.log("input", input); const { PlatformApi } = libraries; let iaf_ext_current_bim_model = PlatformApi.IafScriptEngine.getVar( "iaf_ext_current_bim_model" ); let type_elements_coll = await PlatformApi.IafScriptEngine.getCollectionInComposite( iaf_ext_current_bim_model._userItemId, { _userType: "rvt_type_elements", }, ctx ); console.log("type_elements_coll", type_elements_coll); let distinctRevitFams = await PlatformApi.IafScriptEngine.getDistinct( { collectionDesc: { _userType: type_elements_coll._userType, _userItemId: type_elements_coll._userItemId, }, field: "ElementType", query: { ElementCategory: input.input.ElementCategory }, }, ctx ); console.log("distinctRevitFams", distinctRevitFams); distinctRevitFams = _.sortBy(distinctRevitFams, (type) => type); return distinctRevitFams;},
Fetching and mapping entities with getModelElements#
The getModelElements script complete the following functions:
- Fetches model elements that match the selected category and type in the
rvt_elementscollection, as well as those element's related items from thervt_element_propsandrvt_type_elementscollections. - Maps the properties and type information to each element to construct what we can call 'entities'.
Script configuration in the userConfig#
In the "modelelems" handler, the script function that calls is defined in config.type.entityData.Model Element.script. The reference to the script file that contains the function is defined in modelelems.scriptTypes:
"handlers": { "modelelems": { "scriptTypes": [ "iaf_dt_model_elems", //references iaf_dt_model_elems.js in scripts/NextScriptEngine/scripts/js ... ], "config": { ... "entityData": { "Model Element": { "script": "getModelElements" } }, ... }, ...}
Fetching elements and their related items#
The getModelElements script takes the ElementCategory and ElementType selections to form and run a findWithRelated query:
async getModelElements(input, libraries, ctx, callback) { const { PlatformApi } = libraries; let iaf_ext_elements_collection = PlatformApi.IafScriptEngine.getVar( "iaf_ext_elements_collection" );
let bimQuery = { parent: { query: input.entityInfo, // The follow represents what input.entityInfo may // { // ElementCategory: input.entityInfo.ElementCategory[0] // ElementType: { $in: input.entityInfo.ElementType } // } collectionDesc: { _userType: "rvt_elements", _userItemId: iaf_ext_elements_collection._userItemId, }, options: { page: { getAllItems: true, }, }, sort: { _id: 1, }, }, related: [ { relatedDesc: { _relatedUserType: "rvt_type_elements", }, as: "Revit Type Properties", }, { relatedDesc: { _relatedUserType: "rvt_element_props", }, as: "Revit Element Properties", }, ], }; let elements = await PlatformApi.IafScriptEngine.findWithRelated( bimQuery, ctx );Mapping elements#
With the elements and their related properties and type information, this data is mapped to create an entity with the following data:
| Property | Description |
|---|---|
| _id | The revit element's id |
| "Entity Name" | Combines the revit family, revit type, and system element id |
| modelViewerIds | The package id, which is the id of the graphic element that the object represents |
| properties | The element's properties |
For more information on how these properties are constructed, see the following mapping code:
let entities = elements._list.map((e) => { let properties = {}; if (!_.isEmpty(e["Revit Type Properties"]._list[0])) { Object.keys(e["Revit Type Properties"]._list[0].properties).forEach( (key) => { let currentProp = e["Revit Type Properties"]._list[0].properties[key]; properties[key] = { dName: currentProp.dName, val: currentProp.val ? currentProp.val : "" + " " + currentProp.uom ? currentProp.uom : "", type: "text", }; } ); } if (!_.isEmpty(e["Revit Element Properties"]._list[0])) { Object.keys(e["Revit Element Properties"]._list[0].properties).forEach( (key) => { let currentProp = e["Revit Element Properties"]._list[0].properties[key]; properties[key] = { dName: currentProp.dName, val: currentProp.val ? currentProp.val : "" + " " + currentProp.uom ? currentProp.uom : "", type: "text", }; } ); } let revitFamily = e["Revit Type Properties"]._list[0].properties[ "Revit Family" ] ? e["Revit Type Properties"]._list[0].properties["Revit Family"].val : "No Family"; let revitType = e["Revit Type Properties"]._list[0].properties[ "Revit Type" ] ? e["Revit Type Properties"]._list[0].properties["Revit Type"].val : "No Type"; let sysElemId = e["Revit Element Properties"]._list[0].properties.SystemelementId.val; return { _id: e._id, "Entity Name": revitFamily + "-" + revitType + "-" + sysElemId, properties, modelViewerIds: [e.package_id], }; }); return entities; },