How to show item in revit file using Forge Viewer? - autodesk-forge

We have a web app connected with Autodesk Forge. We were able to upload and view revit files and get the metadata of the file. Now, we want to view specific item in the file without viewing the whole file. How can we make that using the Forge Viewer??

EDIT
The correct option to pass in should be ids and not dbids, been a while since I used this so had to brush up on it...
Yes simply pass in an array of dbids for Viewer to partially load the model:
const options = {
ids: [233,2333 ...]
//...
}
viewer.start/loadModel(svfUrl, options) // or viewer.loadDocumentNode(doc, geom, options)
Note that with this approach there's no option to load the rest of the nodes back w/o reloading the entire model with their dbids passed in again.
Also note that dbids are inconsistent between conversions (they are subject to change if the model is translated again) so use externalIds of a node to map it to a component in the editor space (Revit).

Related

Is it possible to implement the highlight function in Forge Viewer by receiving a specific ID from an external web page?

IFC format project is being viewed with Forge Viewer. IFC project elements (top panel, slab, right wall, etc.) are listed on an external web page, and I want to implement a function that highlights in Forge Viewer when one of them is selected.
Should I use 'GLOBALID' to implement the function?
I've been looking for Forge Viewer's API(v7), but I'm curious if it provides the same functionality as above.
Yeah, it's possible. Here is a sample demonstrating this idea:
https://github.com/yiskang/forge-viewer-iframe-interoperability
This sample supports two ways to locate objects:
By passing querying strings to viewer page's URL (See public/extlink.html):
urn: It stands for which model to load by the Forge Viewer.
idType: It stands for the IFC guid type. If the IFC model is translated by the legacy IFC pipeline, then the idType is GLOBALID. On the contrary, if you're using modern pipeline, the idType is IfcGuid.
guid: It stands for the IFC guid of the object you want to locate.
With those parameters, you can locate objects after model is loading completely immediately by passing them to the URL like the below:
http://localhost:3000/viewer/?urn=dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3bGt3ZWo3eHBiZ3A2M3g0aGwzMzV5Nm0yNm9ha2dnb2YvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X2xlZ2FjeS5pZmM&type=GLOBALID&guid=2cgXCjpDT0ZxBvxMSr3pfm
By triggering LOCATE_ELEMENT_EVENT (See public/index.html):
// Trigger event from iframe's parent page
const guid = event.target.getAttribute('data-guid');
const idType = event.target.getAttribute('data-idType');
if (!idType || !guid) return;
const iframeWind = viewerIframe.contentWindow;
iframeWind.NOP_VIEWER.fireEvent({
type: iframeWind.Autodesk.ADN.ElementLocator.Event.LOCATE_ELEMENT_EVENT,
idType,
guid
});

Forge Api - Search

I am showing multiple IFC files in my forge viewer. Till here everything is fine. What I am struggling with is that I want to find values of an attribute say for name from all the ifc files in the viewer with the values I also need to to that this value has come from which ifc file.
Thanks & Regards
Get the model reference and then call getProperties
for (const model of viewer.getVisibleModels()) {
viewer.isolate(null, model);
}
Model.prototype.getProperties = function(dbId, onSuccessCallback, onErrorCallback)
{...}
We have a multimodal refresher blog, please refer here

how to get URN of clicked object(mechanical equipment ) in forge?

I have created small web app which can able to render revit model using Forge Viewer, now i want to extend to next level. there is any way to fetch URN of each object on click event. here object refer to mechanical equipment.
i want to open new web page with that particular selected object(single object). single object should be there
Not sure if you wanted the selected nodes (parts) of the model selected or visible/loaded only when the page is opened so I'd cover both options here...
You can either select the components/nodes by their dbids soon as the model's loaded (when the model tree is available so nodes can be associated with their dbids):
const selection = viewer.getSelection()
//persist or pass the dbid array as parameter for the new page
//...
NOP_VIEWER.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, e=>{
viewer.select(selection) // or viewer.isolate(selection) depending on your needs
})
Or load the selected components only following here ...

How to load propertyDb for f2d files in local environment

I am using Forge extractor in order to translate model into SVF format and load them in the local environment using Forge Viewer v7. I've selected both 3D Views and 2D Floor Plans from Revit for translation and I can see that they are converted successfully.
I am loading the 3D view using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("Resource/3D View/{3D} xxxxxx/{3D}.svf", options);
I can see that the properties for the elements can be loaded succesfully and I can view the properties/attributes for this element using the Properties Panel.
However, when I am loading a 2D Floor plan (f2d) file using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("2c627223-65bc-e4f4-6518-dda3dc1960dc_f2d/primaryGraphics.f2d", options);
The properties for elements can not be displayed correctly.
May I know is there a way to also display properties for objects in 2D Floor Plan? Thanks!
Unfortunately that extractor has been officially retired recently so we would not be supporting it going forward ...
Try other tools like this, this and this etc to download the SVFs
Coming back to the issues you were experiencing - apparently the property db was not loaded ... see your console output and check for any 404 errors for getting object*.json - these files are the property db...:
attrs: [path + "objects_attrs.json.gz"],
values: [path + "objects_vals.json.gz"],
avs: [path + "objects_avs.json.gz"],
offsets: [path + "objects_offs.json.gz"],
ids: [path + "objects_ids.json.gz"]
Once you use a tool that downloads all the dependencies for f2d derivatives properly or implement the process correctly yourself then everything would be functioning properly again ...

Load Multiple URN in Forge Viewer

When I use ver.2.5 viewer.js. I can load three rvt model (a building, split each three floor to a model) in one viewer, and it fits perfectly.
After I switch to the newest viewer.js (v.2.10), three rvt model will overlap each other.
I check the difference between the v2.5 viewer and v2.10 viewer, and V2.5 has following code:
//If there is already a model loaded, we need to use the same globaOffset as the first model,
//with the assumption that multiple models are loaded into the same space (more or less).
if (this.viewer3DImpl.model && !options.globalOffset) {
options.globalOffset = this.viewer3DImpl.model.getData().globalOffset;
}
How can I get the same result as v2.5 viewer without editing the source of 2.10 viewer?
I had exactly the same problem.
Now, since 2.7, you have to get the globalOffset from your first model and create a globalOffset option to insert in your loadModel query.
var globalOffset = viewer.model.getData().globalOffset; //Get it from first model
var options = {globalOffset: globalOffset}
viewer.loadModel(path, options); //Load your second model