tryGetElement Method

Get an element by Id, FederationGuid, or Code

tryGetElement<T extends Element>(elementId: Id64String | GuidString | Code | ElementLoadProps, elementClass?: EntityClassType<Element>): T extends Element | undefined

throws IModelError if the element exists, but cannot be loaded.

note Useful for cases when an element may or may not exist and throwing an Error would be overkill.

see IModelDb.Elements.getElement

Parameter Type Description
elementId Id64String | GuidString | Code | ElementLoadProps either the element's Id, Code, or FederationGuid, or an ElementLoadProps
elementClass EntityClassType<Element> Optional class to validate instance against. This parameter can accept abstract or concrete classes, but should be the same as the template (T) parameter.

Returns - The element or undefined if the element is not found or fails validation when elementClass is specified.

Defined in

Last Updated: 18 November, 2020