Add FilteredElementCollector memebers to ComboBox in WinForm

Add FilteredElementCollector memebers to ComboBox in WinForm

luisdavid.mena
Enthusiast Enthusiast
660 Views
4 Replies
Message 1 of 5

Add FilteredElementCollector memebers to ComboBox in WinForm

luisdavid.mena
Enthusiast
Enthusiast

How can I add the content of a FilteredElementCollector into a ComboBox that I'm working with inside a WinForm?

 

public Result ListDim(ExternalCommandData commandData, ref string message, ElementSet elements)
{
      //Get Dimension Types
      var dim = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfClass(typeof(Dimension)).WhereElementIsElementType().ToElements();
      //Add to ComboBox
      foreach (Element elem in dim)
         cmbBxDim.Items.Add(elem.Name.ToString());

      return Result.Succeeded;
}

 

I then add the method to the Form event:

 

private void CreateAxis_Load(object sender, EventArgs e)
{
    ListDim(commandData, ref message, elements);
}

 

The WinForm opens but my "cmbBxDim" ComboBox appears empty .

Any help would be appreciated.

 

0 Likes
Accepted solutions (1)
661 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

I think the issue is with your filter criteria i.e. no element is going to satisfy the criteria you have set it up for (stringing criteria together is not treated as 'or' but an 'and').

 

i.e. a Dimension is a Dimension and a FamilySymbol is a FamilySymbol.

If you want to find types filter for class of DimensionType or use category filter with ElementIsElementType.

 

Using WhereElementIsElementType after a class filter is pointless because most class types either represent an instance or a type explicitly. e.g. Dimension and DimensionType or FamilyInstance and FamilySymbol etc.

 

Message 3 of 5

luisdavid.mena
Enthusiast
Enthusiast

@RPTHOMAS108 , Thank you for yor help. It works, but I can only display the names of the Dimension Types that are actually already drawn in my view. What I want is to display ALL the dimension types that I have loaded in my project, not only the already drawn ones. How can I achieve that?

This is what I have so far:

//Get Dimension Types inside the project
IList<DimensionType> DimTypes = new List<DimensionType>();
var dimType = new FilteredElementCollector(doc).OfClass(typeof(Dimension));
foreach (Dimension dim in dimType)
    DimTypes.Add(dim.DimensionType);
//Add to comboBox
foreach (DimensionType c in DimTypes)
    cmbBoxDims.Items.Add(c.Name);
0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

Your collector is not set to a view so it should return dimensions from all views.

 

If you want DimensionTypes then use .OfClass(typeof(DimensionType)) not .OfClass(typeof(Dimension)).

Message 5 of 5

luisdavid.mena
Enthusiast
Enthusiast

@RPTHOMAS108 That's right! DimensionType is the class I was looking for. Thanks!!

0 Likes