Gircsi117
(Gilian Erik)
July 11, 2023, 11:53am
1
Hello!
In React, I’m loading the Revit model with the Viewer. When I click on an element, it returns all the Revit properties of that element.
I would need all the data of each element like this after loading the model. Later on, I will need to create an automated selection system using this data.
Can you help to me?
Thank you in advance for your answers!
jonathon
(jonathon@stardotbmp.com)
July 11, 2023, 12:11pm
2
The viewer provides a tree-like data structure with all the data from the streams it loads:
getDataTree(): DataTree
DataTree
provides several methods for working with the tree structure.
type SpeckleObject = Record<string, unknown>
type ObjectPredicate = (guid: string, obj: SpeckleObject) => boolean
interface DataTree {
findFirst(predicate: ObjectPredicate): SpeckleObject
findAll(predicate: ObjectPredicate): SpeckleObject[]
walk(predicate: ObjectPredicate): void
}
SpeckleObject
is just the generalization of the speckle objects that come from streams
ObjectPredicate
is the function type used by the DataTree
’s members, and it specifies the internal node’s unique id and the speckle object reference. The returned boolean controls when to stop walking the data tree. A false
will terminate the ongoing walk operation
A quick example of usage of the DataTree
:
const dataTree = viewer.getDataTree()
// Get all mesh speckle objects
const objects = dataTree.findAll((guid, obj) => {
return obj.speckle_type === 'Objects.Geometry.Mesh.'
})
Gircsi117
(Gilian Erik)
July 11, 2023, 12:30pm
3
You’re welcome!
However, the retrieved data does not contain all the Revit parameters, only the following ones:
jonathon
(jonathon@stardotbmp.com)
July 11, 2023, 12:35pm
4
In the example I gave it filters by Mesh objects from you selected object example you see it has speckle_type: Revit.RevitInstance
If you were to see if
const objects = dataTree.findAll((guid, obj) => {
return obj.hasOwnProperty('parameters');
});
Only objects with revit Parameters will be returned
1 Like
Gircsi117
(Gilian Erik)
July 11, 2023, 1:50pm
5
Thanks for the help! I have the solution!
1 Like