Weird behaviour when trying to get linked elements visible in newly created view

Weird behaviour when trying to get linked elements visible in newly created view

rcrdzmmrmnn
Advocate Advocate
132 Views
1 Reply
Message 1 of 2

Weird behaviour when trying to get linked elements visible in newly created view

rcrdzmmrmnn
Advocate
Advocate

Hello, I am having this error when trying to retrieve the visible linked elements in a newly created view.

rcrdzmmrmnn_0-1739811667781.png

Specifically when stepping through the new FilteredElementCollector(Doc,View.Id,LinkedElem.Id) constructor.
 Approaches I've tried so far:

-Encapsulating the view creation in a subtransaction and doc.regenerate()
-Getting the linked elements in a manually created view(with success).
-Getting the host elements in this newly created view(with success).

The only case which triggers this error is when using the linked elements overload in the newly created view.

My code is as :


                linkedElem = new FilteredElementCollector(Doc)
           .OfClass(typeof(RevitLinkInstance)).ToElements()[0] as RevitLinkInstance;


                using (SubTransaction st = new(Doc))
                {
                    st.Start();
                    VistaAtiva = CriarPlantaBaixaDoNivel(level);
                    Doc.Regenerate();
                    st.Commit();
                }


                List<BuiltInCategory> listaCategorias = new List<BuiltInCategory>
        {BuiltInCategory.OST_StructuralColumns,BuiltInCategory.OST_StructuralFraming,BuiltInCategory.OST_Floors};
                ElementMulticategoryFilter filtroMultiCategory = new ElementMulticategoryFilter(listaCategorias);


                IList<Element> linkedElements = new FilteredElementCollector(Doc, VistaAtiva.Id, linkedElem.Id)
                    .WherePasses(filtroMultiCategory)
                    .ToElements();
0 Likes
Accepted solutions (1)
133 Views
1 Reply
Reply (1)
Message 2 of 2

rcrdzmmrmnn
Advocate
Advocate
Accepted solution

My solution was to encapsulate the view creation in a transaction, then, commit the transaction. After that, set the Uidoc.ActiveView to the created view. This way, I could retrieve the linked elements in the newly created view without getting memory errors. I still thinks that's a bug, for the reasons I've cited above.
Anyways, I'll mark this post as solved.

0 Likes