Skip to content

linkmaker

Handle creation of output window helper links.

Attributes

mlogger = get_logger(__name__) module-attribute

PROTOCOL_NAME = 'revit://outputhelpers?' module-attribute

Functions

Create link for given element ids.

This link is a special format link with revit:// scheme that is handled by the output window to select the provided element ids in current project. Scripts should not call this function directly. Creating clickable element links is handled by the output wrapper object through the :func:linkify method.

Examples:

output = pyrevit.output.get_output()
for idx, elid in enumerate(element_ids):
    print('{}: {}'.format(idx+1, output.linkify(elid)))
Source code in pyrevitlib/pyrevit/output/linkmaker.py
def make_link(element_ids, contents=None):
    """Create link for given element ids.

    This link is a special format link with revit:// scheme that is handled
    by the output window to select the provided element ids in current project.
    Scripts should not call this function directly. Creating clickable element
    links is handled by the output wrapper object through the :func:`linkify`
    method.

    Examples:
        ```python
        output = pyrevit.output.get_output()
        for idx, elid in enumerate(element_ids):
            print('{}: {}'.format(idx+1, output.linkify(elid)))
        ```
    """
    try:
        try:
            strids = [safe_strtype(x.IntegerValue) for x in element_ids]
        except TypeError:
            strids = [safe_strtype(element_ids.IntegerValue)]
    except AttributeError:
        raise ValueError("One or more items are not ElementIds")

    elementquery = ('element[]={}'.format(strid) for strid in strids)

    reviturl = '&'.join(elementquery)
    link_title = ', '.join(strids)

    if len(reviturl) >= 2000:
        alertjs = 'alert("Url was too long and discarded!");'
        linkattrs_select = 'href="#" onClick="{}"'.format(alertjs)
        linkattrs_show = linkattrs_select
    else:
        base_link = 'href="{}{}{}&show={{}}"'.format(
            PROTOCOL_NAME, '&command=select&', reviturl
        )
        linkattrs_select = base_link.format("false")
        linkattrs_show = base_link.format("true")

    return DEFAULT_LINK.format(
        attrs_select=linkattrs_select,
        attrs_show=linkattrs_show,
        ids=contents or link_title,
        show_icon=LINK_SHOW_ICON
    )