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

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
});

Related

Created DirectShape is not extracted through forge

I generated (in debug mode an addin) DirectShape as a Volume of a Room as in:
https://github.com/jeremytammik/RoomVolumeDirectShape
Rooms are generated and REVIT file is saved correctly, then I send it to FORGE for processing and I extract Model View Metadata Properties (mvmp) and the OBJ.
The issue is that MVMP does not contain any information of recently generated room volumes, the object is:
DirectShape ds = DirectShape.CreateElement(doc, _id_category_for_direct_shape);
ds.ApplicationId = id_addin;
ds.ApplicationDataId = r.UniqueId;
ds.SetShape(geo.ToList<GeometryObject>());
ds.get_Parameter(_bip_properties).Set(json);
ds.Name = "Room_Max_is_an_okayish_dev_" + r.Name;
The question here is: how should I modify it so it will be included in the extraction mvmp.json?
I suspect I need to tag it somehow or add it to some sort of collection.
Please help.
Thank you in advance.
In Revit, you can define which views are to be included in the Forge translation process.
Ensure that you see your direct shapes in at least one of your Revit views, and that this view is earmarked for translation to Forge.

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 show item in revit file using Forge Viewer?

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).

Does Autodesk forge only support 3D model presentations? Can I display a two-dimensional floor plan?

At present, the 3D model is displayed according to the documentation provided by the Autodesk forge official website, but the relevant api or extension is not provided to directly display the 2D floor plan. Please tell me the specific steps, I would be grateful.
For Revit 2D view translation, please check you have picked them in any view sets of the Publish Settings.
In the viewer side, please try to specify a proper view filter role: 2d in your code while loading models. For example,
const filter = {
type:'geometry',
role: '2d' //!<<< the key
};
const rootItem = doc.getRoot();
const viewables = rootItem.search(filter);
viewer.loadDocumentNode( doc, viewables[0] );
Ref: https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/viewer_basics/load-a-model/#step-2-load-model-in-manifest

Is there extension to show the models on a level?

I'd like to make a function to show models on a level which someone selected like a function that we can see in BIM 360 docs.
level selection in BIM 360 docs
Is there such kind of extension?
Try the Autodesk.AEC.LevelsExtension extension - so long as the model comes with the required AEC data about existing floors:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT/Autodesk.Viewing.GEOMETRY_LOADED_EVENT , //wait till design data is loaded
viewer.loadExtension('Autodesk.AEC.LevelsExtension')
)
You can inspect whether your model contains the necessary data using model.getAecModelData()