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: 

How to get elements by view?

6 REPLIES 6
Reply
Message 1 of 7
subpartner
4022 Views, 6 Replies

How to get elements by view?

Hi, I want to get every view's elements, so I will invoke API FilteredElementCollector(document, viewId) to get, but that are some problems with the API. I wrote a function to test, like bellow:

 

private void test(){
FilteredElementCollector viewCollector =

new FilteredElementCollector(m_document).OfCategory(BuiltInCategory.OST_Views);

foreach (Element viewElem in viewCollector)
{
Autodesk.Revit.DB.View curView = viewElem as Autodesk.Revit.DB.View;

if(!FilteredElementCollector.IsViewValidForElementIteration(m_document, curView.Id)) continue;

 

FilteredElementCollector viewElems =

new FilteredElementCollector(m_document,curView.Id).WhereElementIsNotElementType();
}
}

 

afte running test() will increate about 800MB of revit process (test model has 217 views and every view has the average of about 8000 elements) and lead to process crashed. Whether it is normal situation to consume so much memory or memory leak.

But If I change the last statement that remove the second param 'curView.Id' to tun again test(), it consumes very little memory. It means if invoke 'FilteredElementCollector(m_document,curView.Id)' will consumes memory, but invoke 'FilteredElementCollector(m_document)' will almost none. 

 

 

 

6 REPLIES 6
Message 2 of 7
saikat
in reply to: subpartner

Hello

 

Can you please let us know the Revit version, you see the reported behavior in? Will it be possible to proivde a Revit model that does not contain confidential information, that we can test using the code snippet you have provided below.

 

Once we can reproduce the reported crash behavior ay our end, we can ask the Development team to investigate further.

 

Thanks

 

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 3 of 7
subpartner
in reply to: saikat

My revit version is Revit Architecture 2012 Build:20110916_2132 Update Release 2.

so sorry, the model contains confidential information. I think that you can test by any model no need too big, and you can see from  'window Task Manager'  the memory increase obviously.

 

Thanks

Message 4 of 7
saikat
in reply to: subpartner

Hi

 

I did a check again with the RAC BASIC SAMPLE PROJECT rvt file and there was barely any increase in the memory usage.

 

If would greatly help if you can pass on a non-confidential Revt file using which we can reproduce the reported behvior. I can then pass the RVT and VS project with the code you have provided for the Development team to investigate further - after I have been able to reproduce it at my end.

 

thanks



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 5 of 7
subpartner
in reply to: saikat

Hi, In the  I used the rac_advanced_sample_project(the model in the sample folder of revit install path) to run the test() function(the test function has written above) again, running in the view of "3D Views"  ->  "{3D}", if keep the filter like:

FilteredElementCollector viewElems = 

       new FilteredElementCollector(m_document, curView.Id).WhereElementIsNotElementType();

after runing test() will increate about 50MB meomery of revit process. If more biger model will comsume more meomery.

 

But if change to:

FilteredElementCollector viewElems = 

       new FilteredElementCollector(m_document).WhereElementIsNotElementType();

Notice: this statement get element by document not like above by view.

 

After changing and running the test() function, but this time increated almost no meomery.

I don't know whether this is bug, but get elements by document or by view will get the same elements (in 3d view), but why get elements by view will increase so much memory.

 

      thank you.

 

Message 6 of 7
saikat
in reply to: subpartner

Hi

 

Thanks for the update. I followed the exact same steps and

1) with the code which did use the Current view Id, the memory usage increased to 353356K from  346680K - which is about 6600 K or 6.4MB.

2) with the code which did not use the Current View Id, the memory usage increased to 380168 K from 378964 K - which is about 1204 K.

 

All this was tested with 3D view as the current active view and with build # 20120221_2030 (x64).

 

As you can see, the results are not comparable between what I see and what seems to be happening at your end (50 MB mem usage increase). If you have any other system handy, can you test this to see if this is specific to your system. Or, is there a difference between the builds or OS at your end and mine?

 

Thanks

Saikat

 

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 7 of 7
subpartner
in reply to: saikat

Hi, 

        My OS is Win7(X86) and revit version is Build: 20110916_2132 Update Release2. I am not sure if is the different OS or revit version.

 

        But by your datas the filter use current view Id also consume about 5 times than no use view Id, but they are get the same elements, why use current view Id will consume so more memory.

 

       By the way, actually I want to show elements by different views, so I need the 'new FilteredElementCollector(m_document, curView.Id)' to get every view's elements to show. If I can firstly get all elements of document(this time will consume less memory). then classify the elements to every view. Whether exist any API to classify them. Like 'OwnerViewId', but this obviously is null if there are geometry elements.

 

      thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community