Revit API

Reply
Distinguished Contributor
subpartner
Posts: 138
Registered: ‎09-22-2008
Message 1 of 7 (837 Views)

How to get elements by view?

837 Views, 6 Replies
07-09-2012 08:34 PM

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. 

 

 

 

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 2 of 7 (782 Views)

Re: How to get elements by view?

07-26-2012 02:33 PM 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

Distinguished Contributor
subpartner
Posts: 138
Registered: ‎09-22-2008
Message 3 of 7 (763 Views)

Re: How to get elements by view?

08-01-2012 03:00 AM 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

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 4 of 7 (747 Views)

Re: How to get elements by view?

08-03-2012 04:41 PM 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

Distinguished Contributor
subpartner
Posts: 138
Registered: ‎09-22-2008
Message 5 of 7 (705 Views)

Re: How to get elements by view?

09-02-2012 11:19 PM 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.

 

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 6 of 7 (684 Views)

Re: How to get elements by view?

09-04-2012 03:26 PM 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

Distinguished Contributor
subpartner
Posts: 138
Registered: ‎09-22-2008
Message 7 of 7 (677 Views)

Re: How to get elements by view?

09-04-2012 09:18 PM 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.