Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select element from linked file

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
BenoitE&A
5022 Views, 5 Replies

Select element from linked file

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


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
5 REPLIES 5
Message 2 of 6
jeremy_tammik
in reply to: BenoitE&A

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:

 

https://thebuildingcoder.typepad.com/blog/2020/07/selection-link-support-cancel-custom-export-multit...

   

Cheers,

 

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 6
BenoitE&A
in reply to: jeremy_tammik

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 !


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 4 of 6
RPTHOMAS108
in reply to: BenoitE&A

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).

Message 5 of 6
BenoitE&A
in reply to: RPTHOMAS108

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.


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 6 of 6
davidarh
in reply to: BenoitE&A

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.

Post to forums  

Rail Community


Autodesk Design & Make Report