Is there extension to show the models on a level? - autodesk-forge

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

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.

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

Missing rooms issue with generatedMasterView and room material replacement using three.js

1st question: Missing room models
I used the model-derivative api from Forge with generatedMasterViews params to extract room nodes from the cloud Revit model (BIM360Team) it work perfectly fine for some model but I had the missing room issues with others.
Successful translated model
Some of the translated model's room nodes was missing and that's weird because their height and phase are the same and the rooms in 2d view were shown.
2D views has no problem at all
3D room nodes in the same floor were missing
So my question is, are their some limitation to extract the room geometry and convert to .svf files? e.g. publish view setting / view range / crop views / crop region ? or something I'm missing in my request ? I tried to align all the parameter or remove some component (e.g. furniture) but the result still the same. If you guys had noticed this issues before please help, your help would be appreciate.
2nd question: Room mesh and materials
I've write the function to highlight the selected elements and its work with almost every nodes except the room elements.
const highLightElement = (dbId, hexColor) => {
const myMaterial = createMaterial(hexColor)
const instanceTree = viewerApp.model.getInstanceTree()
const fragList = viewerApp.model.getFragmentList()
instanceTree.enumNodeFragments(dbId, function(fragId) {
fragList.setMaterial(fragId, myMaterial)
const fragProxy = viewerApp.impl.getFragmentProxy(viewerApp.model, fragId)
fragProxy.scale = new window.THREE.Vector3(scaleRatio, scaleRatio, scaleRatio)
fragProxy.updateAnimTransform()
}, true)
viewerApp.impl.invalidate(true)
}
The material of the room was gloomy white but if use section tool on it the section color already change to the color I choose (0xAB00EE - magenta). I don't know that is the room mesh different from others? or might be need some special procedure to do so?
Successful coloring nodes
Room nodes coloring
Z-section of colored room nodes
Regarding issue #1, it's possible that there are certain limitations preventing the Forge Model Derivative service from extracting room information but that would be more on the Revit side. If you wouldn't mind sharing the Revit model with us (confidentially) via forge (dot) help (at) autodesk (dot) com, we'd be happy to investigate it with the engineering team. In that case, please indicate which rooms are missing, too.
Regarding issue #2, from the Forge Viewer standpoint, rooms are just another geometry in the scene, with the only difference that this geometry is usually transparent and hidden by default. As far as I know, the visibility flag should not interfere with something like setting the material of a fragment but double-check if that really isn't the root cause.

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

Is it possible to load new Cloud (BIM 360) links in a Revit model either through the Revit API or FORGE API?

I have a two-part WPF App and Revit Addin that runs a series of routines to create and activate a new BIM 360 project via the FORGE BIM 360 API, launches Revit and creates and sets up a collection of Revit models from a "seed" Revit model. The primary requirement is to have zero user interaction in this process: to be fully automated.
Given that background, I am having trouble linking the newly saved BIM 360 models to one-another. I have the option to do this either in the Revit Addin with Revit API hooks (preferred) or through the manager WPF App with FORGE API REST calls after the models are created.
Is either one possible?
I have successfully linked with the cached local models as described here and here. However, this does not meet the requirement fully, since when any other user (besides the automation machine user) opens the model the links are Not Found.
Screenshot of links Not Found.
Current "sort-of-working" code:
var wId = GetWorksetId(doc, w);
if (wId != null)
{
string localPath = settings.CloudModels.Where(x => x.ModelName == _linkModelNames[i]).Select(x => x.LocalFilePath).First();
ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath(localPath);
using (var options = new RevitLinkOptions(true))
{
using (var t = new Transaction(doc, w))
{
t.Start();
doc.GetWorksetTable().SetActiveWorksetId(wId);
using (var result = RevitLinkType.Create(doc, path, options))
{
_ = RevitLinkInstance.Create(doc, result.ElementId);
}
t.Commit();
linkPlaced++;
}
}
}
I was able to get the correct ModelPath via the Revit API thanks to this helpful tip. I can save this value in my Addin, close the model, and access the property later after opening a different model (saved in the CloudModels class referenced in the linq statement in the code snippet above). Unfortunately for me RevitLinkType.Create() that takes a ModelPath does not accept the cloud path, so I may have hit another dead end. Unless it is possible with an ExternalResourceReference. Has anyone tried this option? If so, how do you assemble a Revit ExternalResourceReference? I am not familiar with this process, and looking over this course from AU 2017, I don't see that it necessarily applies to BIM 360 cloud models. A BIM 360 cloud example would be very helpful if this is possible.
Alternate strategy: I do not see any reference to loading links in the FORGE Data Management API or other FORGE APIs. If I have somehow missed it, please share a link.
Any help would be very much appreciated!!
EDIT: I have since found these two (1) (2) similar questions that, at least for my purposes, were not answered satisfactorily. Any updates I should be aware of?
As of now (Jan 2020), unfortunately, we do not have a Link API for cloud models. It is on the roadmap.
Revit API 2022 docs mention that
The methods:
RevitLinkType.Create(Document, ModelPath, RevitLinkOptions)
RevitLinkType.LoadFrom(ModelPath, WorksetConfiguration)
have been enhanced to support creation of new cloud model Revit links.
You may use ModelPathUtils.ConvertCloudGUIDsToCloudPath() to
create a cloud path to use as an argument to these methods.
Additional Resource:
This Youtube Video showcases an example and its respective Github repo.
For Revit 2021 and below, you can use ExternalResourceReference() as a workaround, but I've noticed that this is not always reliable.
Its also mentioned in the documentation of InSessionPath property to not rely on this property:
Do not rely on this path (InSessionPath ) to look up an ExternalResourceReference, as the path is neither unique nor stable. It isn't unique because multiple servers might use the same server name and display name format. It isn't stable because some servers allow renaming, and because a server might change its name at some point.
Below is the code to do that:
var linkCloudPath = doc.GetCloudModelPath(); // the cloudpath of a BIM360 model
Guid linkedmodelguid = linkCloudPath.GetModelGUID();
Guid linkedprojectguid = linkCloudPath.GetProjectGUID();
Dictionary<string, string> Dictionary_ExternalResource = new Dictionary<string, string>(){
{"LinkedModelModelId", modelGuid.ToString()},
{"LinkedModelProjectId", projGuid.ToString()}
};
Dictionary<string, Guid> servers = new Dictionary<string, Guid>();
foreach (var service in ExternalServiceRegistry.GetServices())
{
if (service.Name == "External Resource Service")
{
IList<Guid> server_ids = service.GetRegisteredServerIds();
foreach (var server_id in server_ids)
{
servers.Add(service.GetServer(server_id).GetName(), server_id);
}
}
}
Guid BIM360ServerID = servers["BIM 360"];
ExternalResourceReference ERS = new ExternalResourceReference(BIM360ServerID, Dictionary_ExternalResource, "", "");
RevitLinkOptions options = new RevitLinkOptions(false);
LinkLoadResult result = RevitLinkType.Create(gcdoc, ERS, options);
RevitLinkInstance.Create(gcdoc, result.ElementId);
Please note that this seems to be working fine in Revit 2020, but not in Revit 2021.
I believe it is possible to create links to the Cloud Models in Revit 2019 or higher (with ModelPathUtils.ConvertCloudGUIDsToCloudPath()). You'll need the ProjectGUID and ModelGUID to make the cloud model path.
Regarding the ExternalResource approach, that also works - but it's super messy - you can read the properties associated with existing BIM360 links and you'll see how an ExternalResource is defined for BIM360 links.
Finally - as of today, the Forge Design Automation for Revit approach would not work for you at all:
1. Not possible to open a live cloud workshared model (only published/uploaded models).
2. No network access while you're running in a Design Automation for Revit session.
Good luck...
-Matt