Reputation: 49
Is there a way to get element position information from a Revit project viewed on Forge Viewer? We will be moving elements on Forge Viewer (mostly Family Instances) and I need to find out the new position of the elements after they are moved. It should match with the Revit API LocationPoint data.
Upvotes: 0
Views: 204
Reputation: 9942
When a design file (Revit, or any other supported file format) is processed by the Model Derivative service, and converted into the viewer format (SVF or SVF2), every element is turned into a "fragment" with its own transformation matrix. You can read (and even modify) the fragment information using the Viewer API:
const frags = viewer.model.getFragmentList();
function listFragmentProperties(fragId) {
console.log('Fragment ID:', fragId);
const objectIds = frags.getDbIds(fragId); // Get IDs of all objects linked to this fragment
console.log('Linked object IDs:', objectIds);
let matrix = new THREE.Matrix4();
frags.getWorldMatrix(fragId, matrix); // Get the fragment's world matrix
console.log('World matrix:', matrix);
let bbox = new THREE.Box3();
frags.getWorldBounds(fragId, bbox); // Get the fragment's world bounds
console.log('World bounds:', bbox);
}
And to modify the transformation of a fragment, try the following:
const frags = viewer.model.getFragmentList();
function modifyFragmentTransform(fragId) {
let scale = new THREE.Vector3();
let rotation = new THREE.Quaternion();
let translation = new THREE.Vector3();
frags.getAnimTransform(fragId, scale, rotation, translation);
translation.z += 10.0;
scale.x = scale.y = scale.z = 1.0;
frags.updateAnimTransform(fragId, scale, rotation, translation);
}
Upvotes: 1