Hello the marvelous pyRevit community,
A quick yet big thank you for making pyRevit available to all and allowing users to expand Revit’s possibilities in this way.
Today I come with a question that, despite a lot of effort to solve it on my own through tests and research, I am unable to resolve.
The goal : Output a table with linkify-style buttons (currently select and show commands) capable to host another method (not select and show, but custom method, here specifically Open Family Instance in Family Editor).
At the bottom is the pyRevit native method where I started to dig in to modify the command call.
Here is the prints I get:
('element_ids : ', [<Autodesk.Revit.DB.ElementId object at 0x0000000000002E12 [1953490]>])
('elid : ', <Autodesk.Revit.DB.ElementId object at 0x0000000000002E12 [1953490]>)
('value : ', '1953490')
('strids : ', ['1953490'])
('elementquery : ', <generator object at 0x0000000000002E13>)
('reviturl : ', 'element[]=1953490')
('link_title : ', '1953490')
('base_link : ', 'href="revit://outputhelpers?&command=select&element[]=1953490&show={}"')
('linkattrs_select : ', 'href="revit://outputhelpers?&command=select&element[]=1953490&show=false"')
('linkattrs_show : ', 'href="revit://outputhelpers?&command=select&element[]=1953490&show=true"')
('return_value : ', '<span><a class="elementlink" style="margin-right:0px;padding-right:3px" title="Click to select or show element" href="revit://outputhelpers?&command=select&element[]=1953490&show=false" >1953490</a><a class="elementlink" style="margin-left:0px;padding-left:3px" href="revit://outputhelpers?&command=select&element[]=1953490&show=true"><svg width="14" height="14" viewBox="2 2 20 20" ><path fill="white" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" /></svg></a></span>')
('test : ', '1953490')
1953490
Usual behavior:
This is the link inside the Linkify Button : revit://outputhelpers/?&command=select&element[]=1953490&show=false
My personal test:
This is the link inside the Linkify Button : revit://outputhelpers/?&command=open_family_editor&element[]=1951262
However, I am getting this error.
How should I structure - where should I place the open_family_editor
method?
Currently it is placed in my pyRevit pushbutton script and it works (opens the Family Editor for this specific Family instance) when it is called outside any other logic.
Any help would be highly appreciated as it could open up the door to more interactive output table with such custom command button links at the tip of these buttons.
Thank you in advance for your time and I wish this will be useful to others too.
Adrien
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)))
```
"""
get_elementid_value = get_elementid_value_func()
try:
try:
strids = [safe_strtype(get_elementid_value(x)) for x in element_ids]
except TypeError:
strids = [safe_strtype(get_elementid_value(element_ids))]
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
)