How to get an element host liveing in a linked model?

How to get an element host liveing in a linked model?

Anonymous
Not applicable
1,317 Views
5 Replies
Message 1 of 6

How to get an element host liveing in a linked model?

Anonymous
Not applicable

Dear all,

 

I have an element living in the active document hosted on a wall living in a linked file. All I want to do is to get the host wall in the linked file. 

By using Element.Host I am getting a RevitLinkInstance! 

 

Any solution for this problem?

 

Thank you

0 Likes
Accepted solutions (1)
1,318 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

try using the below code

 

//helps you to select an element(door,window) in the linked document
                Reference R = uidoc.Selection.PickObject(ObjectType.LinkedElement);
                Document linkedDoc = null;
                foreach(Document d in app.Documents)
                {
                    //get the linked document
                    if(d.IsLinked)
                    {
                        linkedDoc = d as Document;
                    }
                }

                Element e = linkedDoc.GetElement(R.LinkedElementId);
                FamilyInstance Fi = e as FamilyInstance;

                Element host = Fi.Host as Element;
                string wallName = host.Name;

 

if there are too many linked documents in the project use 

 

 //get the linked document
    if(d.IsLinked && d.Title=="Your linked document name")
      {
        linkedDoc = d as Document;
      }

 

The important points are

1)To select an object in linked document you have to use object type as LinkedElement

2)Get the linked document not the main document

3)from the linked document using the linked element id get the element present in the linked document

 

If you have any doubts , feel free to ask

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

Anonymous
Not applicable

Dear @naveen.kumar.t ,

Thank you for the fast reply,

I want to follow the exact workflow followed above in the code but instead, I want to select the element in the active document and get its host from the link model.

 

It will be highly appreciated if you can provide an example for that since I am not seeing any link between an element in the active document and its host in a linked one.

 

Thank you,

 

0 Likes
Message 4 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous ,

Try using the below code

//select an element in the active document
      Reference R = uidoc.Selection.PickObject(ObjectType.Element);

//get the linked document
      Document linkedDoc = null;
      foreach (Document d in app.Documents)
          {
              if (d.IsLinked)
                {
                   linkedDoc = d as Document;
                 }
           }

//get the selected main document element
      Element e = doc.GetElement(R.ElementId);
      FamilyInstance Fi = e as FamilyInstance;

//get the Wall from the linked document((wall where the main document element is hosted))
      ElementId hostFacereferenceid = Fi.HostFace.LinkedElementId;
      Element wall = linkedDoc.GetElement(hostFacereferenceid);
      string wallName = wall.Name;

I hope this helps. 

If this helped solve your problem please mark it as the solution, so other users can get this solution as well😊


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 6

Anonymous
Not applicable

Thank you @naveen.kumar.t , That's what I want.

 

One more question please to complete my script, I managed to get the LinkedElementId from the reference but I found that it is unstable of different than the Id of the element in the Linked file. 

What I want is to get the Unique Id in the linked file for this Element(reference)

 

Thank you, appreciated!

0 Likes
Message 6 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Here are the below links which will help you to understand the uniqueId

UniqueId Property 

understanding-the-use-of-the-uniqueid 

unique-id-vs-elementid 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes