I need the export GUID to be included in the translated properties for Revit files
Solved! Go to Solution.
Solved by Daniel.Du. Go to Solution.
Hi Talik,
Just checked with engineering team, GUID is included when translating Revit file for viewer. Can you please double check that? Or please let us know if have problem with that.
I've only tried one model so far, but I'm getting and displaying all the properties and I'm not seeing the Guid. If you contact me off list, I can make my test server available to you.
Hi Talik,
I understand the issue. Actually the unique Id of revit element are included in the model, but it is not included when query with viewer API - viewer.getProperties. I will log a change request on this as an improviment. Thank you for the feedback!
At the same time, would you please elaberate why you want this unique Id as a user story? One usage I can think of is, connecting the element to external database with this unique ID. I would like to hear your user story, how are you going to use this unique ID ?
Please give us an update if GUID is avaiable through GetProperties().
The reason is we use GUID to track object, not dbids. But most methods provided by Viewer3D is using dbids as parameter such as: Viewer3D.select(dbids) ,Viewer3D.solateById(dbids)
Is it possible that those methods can also take GUID as parameter?
Hello,
The guid should be available in the node properties for Revit files. I just responded in this thread:
with code on how to retrieve the guid from the properties and map them to node ids, which you can then use in the various viewer APIs (select, isolate, etc.).
Hope this helps,
John
Am still not seeing the GUID in my property list. Here is the urn for the model. I have tried regenerating it with the force flag.
urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aWJtX3Rlc3Qvb2ZmaWNlX21lcC5ydnQ=
Hi - whatever happened in this thread?
Is there some way to use GetProperties() and retrieve the hidden properties like GUID for Revit objects?
Thanks,
Matt
Hi,
Following code snippet display all properties including hidden ones in viewer, but unfortunately the GUID of revit is still not there, I am checking with development team to find out the reason, and I will report here once I get answer.
Snippet
_viewer.getProperties(dbId, function (result) {
if (result.properties) {
for (var i = 0; i < result.properties.length; i++) {
var prop = result.properties[i];
if (prop.hidden) {
console.log('[Hidden] - ' + prop.displayName + ' : ' + prop.displayValue);
} else {
console.log(prop.displayName + ' : ' + prop.displayValue);
}
}
}
});
Hi everyone,
First of all - an apology:
A few wires became crossed when communicating with our engineering team about the accessibility of Revit GUIDs. While the issue of not being able to read [hidden] properties has been addressed, this doesn't allow you to access Revit GUIDs from the object properties. The reason for this is because those GUIDs are actually stored in a different file, and aren't loaded by the viewer for performance reasons.
I'm sorry that the information we posted here implied you could access those properties, which presumably caused some of you to spend your valuable time tryiong to access them.
We've now asked the engineering team to provide an API to simplify downloading and parsing accessing this separate GUID file, and we hope it will be available in the January production push.
In the meantime, this GUID file is accessible, but it requires a little work that will become obsolete once we create a simple API for you. If you don't want to wait for the API, here is the information you need to access and parse the file:
The GUID file is stored as part of the translated Document bubble. The file is objects_ids.json.gz, and is located at the path given by Document.getPropertyDbPath().
So, for example, the URL to access the GUID file looks something like this:
https://developer.api.autodesk.com/viewingservice/v1/items/urn:adsk.viewing:fs.file:dXJuOmFkc2sub2kqZWN0czpvcy5vYmplY3Q6c2dwXoBlcnNpc3RlbnRidWNrZXQvUmV2aXRUZW1wLnJ2dA==/output/Resource/objects_ids.json.gz?domain=
where the red part is the path returned by getPropertyDbPath(). (To quickly test this, you can construct your own URL using data for your own model and paste it into your browseer address bar to download a local copy of objects_ids.json.gz - this should work as long as you've already authenticated your session).
The file itself is a zipped JSON file that lists an array of GUIDs, where the index of each GUID in the array corresponds to the dbid of the element in the model being viewed.
I'm posting this information now so that those of you who need this urgently can start using it. Someone from my team will post some JavaScript code demonstrating this in the near future (unless someone beats us to it :-).
BTW Some of the confusion over this issue arose because Revit GUIDs are displayed for translations of DWF files exported from Revit. So anotyher way to have access to these GUIDs is to export your RVTs to DWF before translating.
Hi,
I managed to create a sample code snippet to get the GUID of element of revit models:
Snippet
//global variable
var _guidDbArray;
//call this in loadDocument()
function prepareGuidDb(doc) {
//get property db path
var propDbPath = doc.getPropertyDbPath();
console.log('propDbPath:' + propDbPath);
var objectIdDbFullPath = 'https://developer.api.autodesk.com/viewingservice/v1/items/'
+ propDbPath + 'objects_ids.json.gz?domain=' + window.location.hostname;
var xhr = new XMLHttpRequest();
xhr.open('GET', objectIdDbFullPath, true);
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
var accessToken = getAccessToken();
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
var dbs = xhr.response;
var rawbuf = new Uint8Array(dbs);
//It's possible that if the Content-Encoding header is set,
//the browser unzips the file by itself, so let's check if it did.
if (rawbuf[0] == 31 && rawbuf[1] == 139) {
rawbuf = new Zlib.Gunzip(rawbuf).decompress();
}
var str = ab2str(rawbuf);
//console.log(str);
_guidDbArray = str.split(',');
};
xhr.send();
}
function getGuidByNodeId(nodeId) {
var guid;
if (_guidDbArray) {
guid = _guidDbArray[nodeId];
}
return guid;
}
// ArrayBuffer to string
function ab2str(buf) {
var chars = new Uint8Array(buf);
//http://codereview.stackexchange.com/questions/3569/pack-and-unpack-bytes-to-strings
//throw a "RangeError: Maximum call stack size exceeded" exception
//in browsers using JavaScriptCore (i.e. Safari) if chars has a length
//greater than 65536
//return String.fromCharCode.apply(null, chars);
var s = "";
for (var i = 0, l = chars.length; i < l; i++)
s += String.fromCharCode(chars[i]);
return s;
}
To use this snippet, we need to call prepareGuidDb() at LoadDocument, as blow:
Snippet
function loadDocument(viewer, documentId) {
// Find the first 3d geometry and load that.
Autodesk.Viewing.Document.load(documentId,
function (doc) {// onLoadCallback
var rootItem = doc.getRootItem();
var geometryItems = [];
//check 3d first
geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(rootItem, {
'type': 'geometry',
'role': '3d'
}, true);
//no 3d geometry, check 2d
if (geometryItems.length == 0) {
geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(rootItem, {
'type': 'geometry',
'role': '2d'
}, true);
}
//load the first gemoetry
if (geometryItems.length > 0) {
viewer.load(doc.getViewablePath(geometryItems[0]),
null, //sharedPropertyDbPath
function () { //onSuccessCallback
//alert('viewable are loaded successfully');
},
function () { //onErrorCallback
//alert('viewable loading failded');
}
);
}
//For revit, getting guid properties
prepareGuidDb(doc);
}, function (errorMsg) {// onErrorCallback
alert("Load Error: " + errorMsg);
});
}
And I can add event listener for 'selection'
Snippet
_viewer.addEventListener('selection', onViewerItemSelected);
The event handler goes here, output the guid to console:
Snippet
function onViewerItemSelected(event) {
var dbIdArray = event.dbIdArray;
for (var i = 0; i < dbIdArray.length; i++) {
var dbId = dbIdArray[i];
//get guid
var guid = getGuidByNodeId(dbId);
console.log('guid :' + guid);
}
}
Hope this helps, and please let me know if you find issues.
Thank you Daniel. I've marked your code snippet as the 'solution' to this post. The final solution is obviously to provide a simple API to retrieve the unique identifier of an element in the original model file (and not just for Revit). But this is a solution until we get that API.
Hi Yong,
The GUID of revit file is not in the property list, even the "hidden" properties, I shared a code snippet demos how to get GUID, which is marked as solution. Please give it a try and let us know if you have problem.