Hi,
I would like to extend the Revit Lookup to elements in Linked files.
For this purpose I need to be able to retrieve a selected element in the linked file (you can select a Door for example in a linked file with the UI).
Is there a way to do this?
Thanks for your ideas.
Benoit
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Dear Benoit,
Thank you for the initiative and brilliant idea!
Afaik, though, that was already implemented two years ago:
https://thebuildingcoder.typepad.com/blog/2019/01/new-revitlookup-snoops-edge-face-link.html
Furthermore, here is a discussion on picking a linked element:
Cheers,
Jeremy
That is brilliant indeed ! 😉
I'll download this tomorrow and test it right away. I've been waiting for this for... years (the multiple issues with positions in linked elements are a nightmare).
For the selection tool (your other link)... not that brilliant if you ask me ! It works only for a given category which you determine first, not very agile.
The thing is, I would like to have access to Elements that are selected in the UI from Linked file, and I don't think this is possible in the API.
I'll add it in my wish list for Father Christmas (or the API devs).
Thanks Jeremy !
It is class not category based and I assume 'Room' could be replaced with 'Element' perhaps.
It just involved Rooms at the time (not Doors).
I'm not saying the tool is bad, just saying that picking a point to get a Room in a Linked file is not ergonomic.
And I'm back to my previous point, if I can select an Element in a Linked file with the UI, how can I get this selection in the API? I guess I can't, for now.
Hi Benoit, it can be done. Please see the Macro example below where a Window element is selected in the linked model. Hope this helps!
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace PickLinkedElement
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("5EC5C348-E15F-478E-9E88-6876CBE9D21F")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void SelectWindow()
{
var uiDoc = this.Application.ActiveUIDocument;
var doc = this.Document;
Document linkedDoc = null;
Reference pickedObject = uiDoc.Selection.PickObject(ObjectType.LinkedElement, new GroupPickFilterWindow(), "Please pick a window in the linked model");
//Add code to get linked document here.
if (pickedObject != null)
{
var linkedEleemnt = doc.GetElement(pickedObject.ElementId) as RevitLinkInstance;
linkedDoc = linkedEleemnt.GetLinkDocument();
var linkElement = linkedDoc.GetElement( pickedObject.LinkedElementId);
TaskDialog.Show("element", linkElement.Name + " - " + linkElement.GetType().ToString() + " - " + linkedDoc.PathName);
}
}
}
// This filter allows selection of only a certain category in a link instance.
public class GroupPickFilterWindow : ISelectionFilter
{
private RevitLinkInstance m_currentInstance = null;
public bool AllowElement(Element e)
{
// Accept any link instance, and save the handle for use in AllowReference()
m_currentInstance = e as RevitLinkInstance;
return (m_currentInstance != null);
}
public bool AllowReference(Reference refer, XYZ point)
{
if (m_currentInstance == null)
return false;
// Get the handle to the element in the link
Document linkedDoc = m_currentInstance.GetLinkDocument();
Element e = linkedDoc.GetElement(refer.LinkedElementId);
// Accept the selection if the element exists and is of the correct type
if (e.Category != null && e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Windows))
{
return true;
}
else
{
return false;
}
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.