Determine linked elements present in a section

Determine linked elements present in a section

wl_santanna
Explorer Explorer
603 Views
3 Replies
Message 1 of 4

Determine linked elements present in a section

wl_santanna
Explorer
Explorer

I have a section with some project elements, and a linked file loaded with some elements in the view, as shown in the attached photo. I need to check which elements of the linked file are present in this section, but I'm having difficulties. 

 

Captura de tela 2024-01-10 084739.png

 

 

I tried to check if the elements are inside the view's BoundingBox, but without success:

 

 

foreach (RevitLinkInstance docsVinculados in vinculosCarregados)
{
Document doc_vinculo = docsVinculados.GetLinkDocument();

RevitLinkType type = Doc.Document.GetElement(docsVinculados.GetTypeId()) as RevitLinkType;

if (RevitLinkType.IsLoaded(Doc.Document, type.Id))
{

Transform posicao_vinculo = docsVinculados.GetTransform();

ICollection<Element> conexoes_vinculo =
new FilteredElementCollector(doc_vinculo).OfCategory(BuiltInCategory.OST_PipeFitting).ToElements().Where(x => x is FamilyInstance).ToList();

foreach (FamilyInstance itemconex in conexoes_vinculo)
{

var posicaoTagConex = itemconex.get_BoundingBox(Doc.Document.ActiveView).Max.Add(posicao_vinculo.Origin);
var posicaominimaConex = itemconex.get_BoundingBox(Doc.Document.ActiveView).Min.Add(posicao_vinculo.Origin);

var DifPosX = (posicaoTagConex.X - posicaominimaConex.X);
var DifPosY = (posicaoTagConex.Y - posicaominimaConex.Y);
var DifPosZ = (posicaoTagConex.Z - posicaominimaConex.Z);

XYZ PosicaoFinal = new XYZ(posicaoTagConex.X - (DifPosX / 2), posicaoTagConex.Y - (DifPosY / 2), posicaoTagConex.Z - (DifPosZ / 2));

BoundingBoxXYZ boundingBox_view = Config.doc.ActiveView.get_BoundingBox(Config.doc.ActiveView);

Then I tried to apply the solution present here:

https://forums.autodesk.com/t5/revit-api-forum/check-to-see-if-a-point-is-inside-bounding-box/td-p/4354446

if (BoundingBoxXyzContains(boundingBox_view, PosicaoFinal))
{

}

}
}
}

 

 

Looks like the position returned in BoundingBox is outside of view. I use this solution to apply tags to linked elements without any problems (I left the code below just for example, as it is not part of the question):

 

 

Reference refe = new
Reference(itemconex)
.CreateLinkReference(docsVinculados);

IndependentTag tagConexao = IndependentTag.Create(
Doc.Document, TagConexSelecionada.Id, Doc.ActiveView.Id, refe,
true, TagOrientation.Horizontal, PosicaoFinal);

 

 

0 Likes
Accepted solutions (1)
604 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

The biggest challenge is probably the transformation. One possible approach would be to read and understand in depth all the transformations involved. Another possible approach, in case your tendency is stronger to hack and do rather than study and ponder, might be: create a very simple linked file with just an element or two, e.g., model lines. Host it. Analyse the resulting geometry in the host file. Reproduce the model lines in the host file until their appearance matches the original ones in the linked file. Basically, you just need to determine where a given bounding box in the linked file will end up on the host, don't you?

  

Since you mention that you can successfully and automatically create tags for the linked elements, another idea comes to mind: before creating the tags, subscribe to the DocumentChanged method to be notified of the added elements. Then, you can query the tags for their locations. That will presumably approximate the host project locations of the linked elements.

  

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

wl_santanna
Explorer
Explorer

Hi Jeremy, thank you for your reply, you just opened my mind to a possible solution! I just add a new IndependentTag then check if it's BoundingBox is valid:

 

 

IndependentTag tagConexao = IndependentTag.Create(
Config.doc, Config.doc.ActiveView.Id, refe,
true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, PosicaoFinal);

if (null != tagConexao.get_BoundingBox(Config.doc.ActiveView))
{
// The element is in the view
}

 

 

Then i collect the id's i need and RollBack the transaction in the final, it's working. Btw i'll study how transformations works when i have linked elements in some view. Thank you

0 Likes
Message 4 of 4

rcrdzmmrmnn
Advocate
Advocate

A new overload for the FilteredElementCollector class was added in revit 2024. It allows the user to input a linked document and retrieve the visible linked elements in a host document view.

ApiDocs.co · Revit · FilteredElementCollector Constructor (Document, ElementId, ElementId)

Constructs a new FilteredElementCollector that will search and filter the visible elements from a Revit link in a host document view.

0 Likes