List of parameters associated to the category

List of parameters associated to the category

Anonymous
Not applicable
1,304 Views
1 Reply
Message 1 of 2

List of parameters associated to the category

Anonymous
Not applicable

Hi Everybody,

 

I am trying to get the parameters for each category in an EMPTY project. The code I am using is:

 

            var document = commandData.Application.ActiveUIDocument.Document;
           
            FilteredElementCollector collector = new FilteredElementCollector(document);       
            var elements = collector.WhereElementIsElementType().Where(w => w.Category != null && w.Category.CategoryType == CategoryType.Model).ToList();

            var dictionary = elements.GroupBy(w => w.Category.Id.IntegerValue).ToDictionary(w => w.Key, w => w.ToList());

 

The problem is this code do not catch all categories, for example Air Terminals. 

 

Any help is welcomed.

 

Thanks,

 

Javi

0 Likes
1,305 Views
1 Reply
Reply (1)
Message 2 of 2

FAIR59
Advisor
Advisor

a schedule has the requested information. Make a schedule with the temporary transaction trick and find all the parameters.

public List<ElementId> categoryparameters (Document doc, Category cat)
{
	if (cat==null) return null;
	List<ElementId> paramIds = new List<ElementId>();
	using (Transaction tr = new Transaction(doc,"make_schedule"))
	{
		tr.Start();
		// Create schedule
      		ViewSchedule vs = ViewSchedule.CreateSchedule(doc, cat.Id);
      		doc.Regenerate();
		
      		// Find schedulable fields
      		foreach (SchedulableField sField in vs.Definition.GetSchedulableFields())
    		{
			if (sField.FieldType != ScheduleFieldType.ElementType) continue;
      			paramIds.Add( sField.ParameterId);
      		}
      		tr.RollBack();
	}
	return paramIds;
}

 

 

0 Likes