PDA

View Full Version : Filter selected elements?



Elizabeth Shulok
2008-06-07, 05:11 PM
I'm writing a command that will work on either all elements in the model or only elements that are selected (ActiveDocument.Selection). I want to use the Filter capabilities so I can get all the beams, then all the walls, then all the point loads, etc. But the only way I can see to use the Filter class is to filter all of the elements in the document. Is there some way to filter just the elements in the Selection set?

Or, is there any way to tell if a given element is selected if it is not retrieved through the Document.Selection property?

Thanks,

mmason.65315
2008-06-07, 11:16 PM
I don't think that there's any efficient way to do what you're suggesting... You could run the filter first, then check that against the selected elements - but that'd be horribly inefficient.

I'd say filtering is pretty much just for when you want to run agains the whole model.

-Matt

GuyR
2008-06-07, 11:58 PM
Filters are the way to go. A filter for each category of object you're interested in while excluding the already selected objects.

Guy

mmason.65315
2008-06-08, 01:42 PM
Guy,

Wouldn't it depend on the size of the model? I haven't done much testing of filters on very large models, but I have to believe that it's much slower to run a complex filter test (types? categories and types?) against a large model than test the handful of elements you have selected for their type?

-Matt

GuyR
2008-06-08, 08:23 PM
but I have to believe that it's much slower to run a complex filter test (types? categories and types?) against a large model

Unless the user has selected the whole model then having the user select certain elements will be quicker. However that's about it. I don't know what mad person told you it's slower on complex filters, certainly won't be me ;-)

Sure they're quirky , performance varies depending on how you've set them up , which options you use etc but Filters finally make the API usable for real world projects. A truely amazing bit of programming IMO and by a huge margin the most significant update to the API in it's short history. The only minor issue for me is they can't be multi-threaded.

Guy

mmason.65315
2008-06-09, 01:06 AM
Nope - sorry I wasn't clear... I was just comparing filters versus looking at the elements that were selected using the traditional tools.

Agreed that filters have vastly improved the landscape... Although it seems like the category filter that is far-and-away the winner (but category is not really definitive on something like walls, since you'll get both "Walls" and "WallStyles").

-Matt

GuyR
2008-06-09, 01:48 AM
(but category is not really definitive on something like walls, since you'll get both "Walls" and "WallStyles").-Matt

It's all objects related to walls. So if you're doing a command that say allows a user to change a wall type for a selection of walls you get the types for free. So I don't have a problem with category behaviour. In terms of getting the instances, the 3 different ways I use all have about the same overhead and <10ms of overhead on ~100MB models.

Like I say for me anyway this is a game changer , if they were thread safe and fixed 2 logged performance slugs in the API I'd be deliriously happy ;-)

Guy

Elizabeth Shulok
2008-06-09, 09:03 PM
Thanks for the feedback, guys. But I'm not sure I understand your suggestion, GuyR.


Filters are the way to go. A filter for each category of object you're interested in while excluding the already selected objects.

Guy
So how would you suggest getting all of the walls, for example, from a set of selected elements?

Thanks,

GuyR
2008-06-09, 09:36 PM
Elizabeth,

I'm assuming you want to get all walls except those selected by the user? So you build a series of filters based on the selected walls you don't want and one filter for all walls.

There are 2 ways off the top of my head you could structure the filters , I'm not sure which will be faster. You'd need to experiment. You might find for logic purposes playing with the elementfilter sample useful. Won't be any good for performance testing but might help you work out the logic.

HTH,

Guy

Elizabeth Shulok
2008-06-09, 10:06 PM
Guy,

Thanks for the response. I think my initial question may have been unclear. I have a command that will either be performed on all elements, or only the elements that they have selected (the user will tick a box when they initiate the command). So, as part of this, I want to do something with the walls - either all of the walls, or just the walls that are part of their selection. This is different than the scenario you described.

If they want the command to work on the entire model, this is easy enough to do with filters for each of the categories of element my command works on. If they want the command to work on just the selected elements, this is also easy enough to do by going through each item in the selection and looking at its type and then performing the appropriate step.

However, I was hoping to loop through the elements in a similar way, regardless of whether the command was to be performed on all elements or just selected elements. Any thoughts?

Thanks,

GuyR
2008-06-09, 10:24 PM
oh... Unless I'm missing something wouldn't this work (psuedo code)

if (Selection.Elements.Count != 0)
{
ProcessWalls(Selection.Elements.Iterator);
}
else
{
ProcessWalls(ActiveDocument.ElementIterator);
}

void ProcessWalls(ActiveDocument.ElementIterator itor);
{
while(itor.MoveNext())
{
// process wall
}

Guy

Elizabeth Shulok
2008-06-09, 10:35 PM
Yes, that will work. But I want to process beams, boundary conditions, etc, in a similar way, and using a similar process, I would be iterating through all the elements multiple times.

The alternative that I am doing is to get the iterator for all the elements, or just the selected elements, then loop through, check the type for each element, passing along each element I care about to an appropriate function to be processed.

I thought using filters might be quicker and more elegant, but in most cases, I don't need to process all of the walls, beams, etc, together as a group and can just process them as I get to them.

I was hoping a filter could be applied to the Selection the way it can be applied to all Elements in the Document, and that I was just missing something.

Thanks again for your reply.

GuyR
2008-06-09, 11:32 PM
But how many elements are being selected? As I said unless they're selecting nearly the whole model on the screen (and even then ) performance should be very good. Definitely use a filter on the allmodel iterator. So the line in my pseudo code should be ProcessWalls(ActiveDocument.ElementIterator(filter));

Guy