简体   繁体   中英

Autodesk Forge Viewer: categoryFilter for getBulkProperties2 not working at all

I've got an Autodesk Forge Viewer toolbar extension for which I'm attempting to retrieve a filtered list of elements from the current model. I'm attempting to use getBulkProperties2 for this since it specifically includes categoryFilter in the options object, which would (hypothetically, at least) save me from having to pull everything and do the filtering manually.

I've wrapped the call to getBulkProperties2 in a promise to make it easier to deal with:

function getBulkProperties(model, dbIds, options) {
    return new Promise(function (resolve, reject) {
        model.getBulkProperties2(dbIds, options, resolve, reject);
    });
}

From there, I make a call to this function once the model has been successfully loaded by adding an event listener and including it in the callback:

viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, async function (e) {
    var props = await getBulkProperties(viewer.model, AllDbIds, { categoryFilter: ["Revit Rooms"] });
});

Unfortunately, with the categoryFilter option configured this way, the result is always an empty array. I've tried several different configurations of this but the result is always the same.

If I make the same request omitting the categoryFilter option and filter the list manually in the browser console, I can see that the elements I'm looking for do in fact exist, in exactly the configuration I'm looking for:

› props.filter(p => p.properties.some(v => v.displayName == 'Category' && v.displayValue == 'Revit Rooms')).length
‹ 113

Does this mean the categoryFilter just doesn't work? Or am I somehow not using it correctly?

Note that the categoryFilter refers to property categories (for example, "Identity Data"), not Revit categories (like the "Revit Rooms" in your example).

https://imgur.com/a/5ipSnMc

If you only want to fetch the properties for "Revit Rooms", you could probably try and find the "Rooms" object in the model browser, find the dbIDs of all its children, and then pass those dbIDs to the getBulkProperties2 method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM