Community
Fusion Educators
Are you an educator who uses Fusion (formerly Fusion 360) in their courses in secondary and post-secondary? This is the official Autodesk forum for educators like yourself to share the success you are having with Fusion in the classroom.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need GUID in Revit model properties

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
Anonymous
4277 Views, 0 Replies

Need GUID in Revit model properties

I need the export GUID to be included in the translated properties for Revit files

 

24 REPLIES 24
Message 2 of 25
Daniel.Du
in reply to: Anonymous

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.



Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 3 of 25
Anonymous
in reply to: Daniel.Du

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.

 

Message 4 of 25
Daniel.Du
in reply to: Anonymous

Hi Talik,

GUID is not visible in property panel. Did you try to get it through API?


Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 5 of 25
Anonymous
in reply to: Daniel.Du

Yes, I am using the API and the 3DViewer class so there is no default property panel

Message 6 of 25
Daniel.Du
in reply to: Anonymous

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 ?



Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 7 of 25
Anonymous
in reply to: Daniel.Du

We want to correlate viewer data with data exported from Revit, typically via the COBie toolkit, but other means such as a plug-in may be used. We will need similar behavior for IFC files. I'm also logging an enhancement request that goes into more detail
Message 8 of 25
Daniel.Du
in reply to: Anonymous

Hi,

Thank you for the story. A new improvement on getProperties have been implemented and will be pushed to live soon. It allows you to get the 'hidden' properties like GUID. Thank you for the patience.


Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 9 of 25
Anonymous
in reply to: Daniel.Du

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?

 

 

Message 10 of 25
john.tan
in reply to: Anonymous

Hello,

 

The guid should be available in the node properties for Revit files.  I just responded in this thread:

 

http://forums.autodesk.com/t5/View-and-Data-API/How-to-get-object-s-DBID-from-its-GUID/m-p/5226933#M...

 

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

Message 11 of 25
Anonymous
in reply to: john.tan

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=

 

 

Message 12 of 25
Daniel.Du
in reply to: Anonymous

Hi talik,

I was told that the updated API is live, but I did not see any changes as well. I am checking with development team, will update you when I find something. Thank you for the patience.


Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 13 of 25
Anonymous
in reply to: Daniel.Du

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

 

Message 14 of 25
Daniel.Du
in reply to: Anonymous

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


                }
            }
        });


Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 15 of 25
StephenPreston
in reply to: Daniel.Du

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.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 16 of 25
Daniel.Du
in reply to: StephenPreston

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.

 

 



Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 17 of 25
StephenPreston
in reply to: Daniel.Du

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.

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 18 of 25
Anonymous
in reply to: Anonymous

we also want to use GUID to track objects. for dwfx files, it's fine to use John's method to get guids. but for revit files, there is no guid available.
As Daniel mentioned that viewer's getProperties could get "hidden" properties like GUID.
Hi Liminhe, has you been able to get revit's guid?
Thanks
Message 19 of 25
Daniel.Du
in reply to: Anonymous

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.



Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 20 of 25
Anonymous
in reply to: Daniel.Du

Hi Daniel,

 

I was able to get revit's guid based on your code.

 

Thanks

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report