How can I get the reference for a face that is queried from a linked project?

How can I get the reference for a face that is queried from a linked project?

208ramyy98
Participant Participant
905 Views
8 Replies
Message 1 of 9

How can I get the reference for a face that is queried from a linked project?

208ramyy98
Participant
Participant

Now, I have a link in my Revit document, from which I queried some Revit elements, such as walls, floors and ceilings, now I created some algorithm to select some faces, only to find that the "Reference" property in those faces to be null. 
How can I get the references for these faces, so that this property is not null. 

0 Likes
906 Views
8 Replies
Replies (8)
Message 2 of 9

jeremy_tammik
Alumni
Alumni

That is a very valid question, and I believe it is not completely trivial to solve. One possibility might be to use some variation of the reference stable representation voodoo. Personally, my approach to try to address this would be a different one, though: I would identify what geometric characteristic or relationship can be used to identify the target face based on the host local coordinate system. It may be identified by its dimensions, location, orientation, or other properties. Then, go into the linked file, retrieve the host element there, query and traverse its geometry, and use the identification properties that you defined to pick the corresponding object. I hope you follow what I mean. Please let us know how you end up solving this nice task.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 9

208ramyy98
Participant
Participant
Well, my script is actually in Rhino.Inside Revit, I already got the Ids of the faces I want, I also have a corresponding list of elements, I just filtered the solids of each of these elements to get the faces with the same Id, that's how I got the faces I want along with their the references.
However, after doing all that I realized that I can't create a family instance on the face of an element in a linked document (Not sure if that's a limitation in Revit), which was the original intent to the script.
Let me explain what I'm trying to do in general, I have a list of elements in my document, these elements were hosted on elements on the link that were later deleted, so these elements became orphaned, my script aims to introduce hosts to these orphaned elements, by recreating them on the closest surfaces to these elements.
0 Likes
Message 4 of 9

jeremy_tammik
Alumni
Alumni

Yes. The reference is tied to the document A. So, to work in a different document B, you need to somehow match and find the corresponding geometry in B and the retrieve a reference to that instead. Some different ways to retrieve references are: pick interactively, use the Geometry property with ComputeReferences = true, use a ReferenceIntersector, etc.

     

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 9

Moustafa_K
Collaborator
Collaborator

I believe placing a face-based family over a linked face is possible using this method.

First, get the faces from the linked document using get_Geometry. Then, extract the references from these faces.

 

Next, translate the references to the current document using:

 

var linkedReference = originalReference.ConvertToStableRepresentation(linkedDocument);

 

 

Finally, place the family:

 

Trans.Start(); // start transaction
Doc.Create.NewFamilyInstance(
    linkedFaceReference,
    linkedFaceReference.GlobalPoint,
    XYZ.BasisZ,
    famSymbol
);
Trans.Commit(); // commit Transaction

 

 

To accurately place the family, you need to ensure that the point where the family instance will be placed corresponds to the linked document's coordinates. Since you already have the point in the current document, use the linked instance's transform to convert this point to the corresponding position in the linked document.

 

Once transformed, project this transformed point onto the faces you've extracted from the linked element's geometry. Identify the nearest face to this projected point. You can then use this projected point, and transform it back to the current document's coordinate system,  and now you can use it as an argument instead of linkedFaceReference.GlobalPoint in the example above.

 

I can't say this is the best approach, but logically this should work. 

 

For a detailed explanation of a similar method, you can refer to my summary here.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 6 of 9

fwang52MYR
Contributor
Contributor

Hi Moustafa -

 

How do I convert a stable reference in a linked document to the current document, I assume that is what is needed for the Create.NewFamilyInstance() method?

 

E.g. in your example code, how is the 'linkedReference' (a string) being converted to 'linkedFaceReference' (a Reference object)?

 

I'm stuck on the reference part, but the full question and demo code is in this question thread that I've posted: Create Hosted Element onto Linked Revit Element by PickObject - Autodesk Community - Revit Products

 

Thanks!

0 Likes
Message 7 of 9

jeremy_tammik
Alumni
Alumni
0 Likes
Message 8 of 9

fwang52MYR
Contributor
Contributor

Hi Jeremy -

I appreciate your response.

I'm trying to programmatically place lighting fixture onto a face of a linked model in the project. I've tried many ways to create reference, but they all gave me error and would not create the family instance.

I'm able to get the linked document, the surface/face that I'm trying to create the instance on and the reference for that face. But it somehow still gives me error.

fwang52MYR_1-1728486789784.png


I'm trying to create face-hosted element the same way in this blog post.
https://thebuildingcoder.typepad.com/blog/2014/07/createlinkreference-sample-code.html

 

Thanks

0 Likes
Message 9 of 9

fwang52MYR
Contributor
Contributor
Quick update:

It ended up being a problem with the direction vector, not reference...
Just hope the error message could be more useful. But its solved now, thank you anyhow!
0 Likes