Getting meters instead of English feets from Autodesk Forge - autodesk-forge

I'm using Autodesk Forge via the official Node.js SDK. All dimensions in my Revit model are set in meters, but, for some reason, when I retrieve the model from Forge, I get everything in English feets (preliminary I convert my .rvt file to .nwc). While I can convert feets to meters on my own, this is really inconvenient. Is there any straightforward way to get everything in meters?

Unfortunately, this might be not possible. According to my experience, it depends on the internal units of the source model. For example, the internal length units of the Revit model is English foot, so the units of the svf, the translated result format of the Forge, will still remain foot. Forge model loader won't change this during loading model, although the default units of the Forge Viewer is meter. We apologize for any inconvenience caused. However, there is a helper function to help you convert units in the Forge Viewer like this:
var length = 1; // 1 feet
var lengthConverted = Autodesk.Viewing.Private.convertUnits( viewer.model.getUnitString(), 'm', 1, length );
Hope this help.

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

In a forge web app, trying to get the unit's old short name from the new Revit 2021 units

I am developing a web application (using javascript) which uses forge viewer API.
In the application I display values of certain properties to the user.
I use Autodesk.Viewing.GuiViewer3D.getProperties to get the properties and from there find he specific property I want.
I believe I get an object of type PropertyResult (https://forge.autodesk.com/en/docs/viewer/v7/reference/globals/PropertyResult/) for this example will assign it to "prop".
Then I display the property value with the unit by (assuming I know it is a number and has units):
var res = prop.displayValue.toFixed(2) + " " + prop.units;
This worked as we wanted when used on models from revit 2019 or 2020.
Showing for example:
"102.79 m^2"
However in model from revit2021 it will show:
"335.59 autodesk.unit.unit:squareMeters-1.0.1"
I realize this happened because of the unit change in RevitAPI for 2021, however I have been trying to find a JS method to get the user friendly name from the new Autodesk unit type and wasn't able to find one.
Will appreciate if anyone can direct me to that method or offer an alternative solution.
Thank you,
This is a known problem that we've discovered recently. Unfortunately, there's no official workaround, and so if you need to compose measurements with units, for now you would have to map the Revit 2021 unit IDs to their display variants, e.g., mapping autodesk.unit.unit:squareMeters-1.0.1 to m^2.
Please stay tuned to the Model Derivative service changelog.

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.

GIS: How to resize layer using .prj (WKT) projection? (Geographic Coordinate System)

Briefly:
How to parametrize .prj WKT file so that I can perform 7 point tranformation (wiki). I know how false_easting and false_northing params work, but how can I adjust scale? I do not mean scale_factor'
That's the problem description:
I have transportation network (vector layer) saved in non-GIS environment (transport modeling software). Network consists of nodes (points) and polylines (road links). It's done mostly from random backgrounds, regardless any projection, coordinates, etc.
I need to set appropriate projection for the network.
I have accesss to .prj files (if I'm in an say WGS84 projection I can switch to any other projection)
So that's what I'm trying:
I try 7 point Helmert Transformation (http://proj.maptools.org/gen_parms.html). I use towgs84 transformation as a WKT param in .prj file, where I assume that rotation matrix is zero (can I do so?) and I calculate only delta_x, and delta_y, and scale param.
However it will not work. This is my .prj , params in TOWGS84 do not affect transformation:
PROJCS["UTM 17 (WGS84) in northern hemisphere.",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563],
TOWGS84[0,0,0,0,0,0,100000000000000000000000]],
PRIMEM["Greenwich",0],
UNIT["DMSH",0.0174532925199433],
AXIS["Lat",NORTH],
AXIS["Long",EAST],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0]]
So I tried to use false_norting and false_easting params, and those work good, and transform my network proprely, BUT:
It will not chcange scale of my network, only position. So how can I rescale my network using .prj file?
Thanks for any hints
Problem solved: both 'scale_factor' , and UNIT['Meter',%scale_factor] works only if datum changes.
Actually comments at the same problem at gis.stackexchange.com/ here brought me to solution.
Anyway: .prj files, Geo Coordinate Systems, proj4js, EPSG etc. are vary weakly documented: no API, no tutorials, no examples, no refernces.
i.e.
1)not any straighforward description of what EPSG database codes are, and which should be chosen.
2)what +proj parameters should I choose to define projection
3)how to create .prj and what are parameters of specific .prj file elements.
awful programming area!