5 Oct 2016
Entity Handle from DWG file in Viewer

When you open a model in the Viewer that was created from a DWG file then you might want to be able to check the Handle value of the selected entity.
This is something that you can get from the object's properties through externalId:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used in blog post http://adndevblog.typepad.com/cloud_and_mobile/2016/10/entity-handle-from-dwg-file-in-viewer.html | |
function addSelectionListener(viewer) { | |
viewer.addEventListener( | |
Autodesk.Viewing.SELECTION_CHANGED_EVENT, | |
function (event) { | |
var firstId = event.dbIdArray[0]; | |
if (firstId) { | |
viewer.getProperties(firstId, function (displayProperties) { | |
alert(displayProperties.externalId); | |
}); | |
} | |
} | |
); | |
} |
As Jeremy mentioned it in the comments section, if the source seed CAD file is a Revit RVT model, the externalId will return the Revit element UniqueId property.