I'm working on a plugin that batch processes global settings. I am facing a problem: I can't get values for "Group parameter under": Not all values are included in this list.
What am I doing wrong?
static public List<string> AddingGroupingOptionsToDictionary(Document _doc)
{
List<string> parameterGroupNames = new List<string>();
FilteredElementCollector collector = new FilteredElementCollector(_doc)
.WhereElementIsNotElementType();
foreach (Element elem in collector)
{
foreach (Parameter param in elem.Parameters)
{
BuiltInParameterGroup group = param.Definition.ParameterGroup;
string groupName = LabelUtils.GetLabelFor(group);
if (!parameterGroupNames.Contains(groupName))
{
parameterGroupNames.Add(groupName);
}
}
}
return parameterGroupNames;
}
Thanks in advance for your reply!
Solved! Go to Solution.
Solved by 2lenin-off. Go to Solution.
I'm not sure offhand. It looks like you are going through every parameter of every element in the file, and getting that parameters group. It seems like there should be an easier way. At any rate, it makes testing the code very difficult.
When I compile, I get 3 warnings. Maybe try using these newer methods? See the attached image.
Try something like this;
For some reason, I got a lot of errors with parameters that don't seem to have group names, hence the "try-catch" statement. (If you uncomment the "TaskDialog.Show " line in the catch statement, be prepared to hit escape a whole lot of times.)
List<string> parameterGroupNames = new List<string>();
FilteredElementCollector collector = new FilteredElementCollector(doc)
.WhereElementIsNotElementType();
string grpnames = "";
foreach (Element elem in collector)
{
foreach (Parameter param in elem.Parameters)
{
try
{
ForgeTypeId grpID = param.Definition.GetGroupTypeId();
string groupName = LabelUtils.GetLabelForGroup(grpID);
//string groupName = LabelUtils.GetLabelFor(group);
if (!parameterGroupNames.Contains(groupName))
{
parameterGroupNames.Add(groupName);
grpnames = grpnames + groupName + "\r\n";
}
}
catch
{
//TaskDialog.Show ("Error", "Cant get group name");
}
}
}
//return parameterGroupNames;
TaskDialog.Show ("Group Names", grpnames);
I hope there is a method that will accomplish this task without errors and much easier.
I get a lot of parameters that are not in the list.
So, with all the options for forming the list, I either got extra elements, or some elements were missing.
As a result, I compiled a list of elements myself: I hope it will be useful to someone.
static public List<BuiltInParameterGroup> CreateGroupParameterList()
{
List<BuiltInParameterGroup> groupParameters = new List<BuiltInParameterGroup>();
groupParameters.Add(BuiltInParameterGroup.PG_ANALYTICAL_MODEL);
groupParameters.Add(BuiltInParameterGroup.PG_VISIBILITY);
groupParameters.Add(BuiltInParameterGroup.PG_SECONDARY_END);
groupParameters.Add(BuiltInParameterGroup.PG_ANALYTICAL_ALIGNMENT);
groupParameters.Add(BuiltInParameterGroup.PG_DIVISION_GEOMETRY);
groupParameters.Add(BuiltInParameterGroup.PG_GRAPHICS);
groupParameters.Add(BuiltInParameterGroup.PG_DATA);
groupParameters.Add(BuiltInParameterGroup.PG_CONSTRAINTS);
groupParameters.Add(BuiltInParameterGroup.PG_IDENTITY_DATA);
groupParameters.Add(BuiltInParameterGroup.PG_MATERIALS);
groupParameters.Add(BuiltInParameterGroup.PG_MECHANICAL);
groupParameters.Add(BuiltInParameterGroup.PG_MECHANICAL_LOADS);
groupParameters.Add(BuiltInParameterGroup.PG_MECHANICAL_AIRFLOW);
groupParameters.Add(BuiltInParameterGroup.PG_MOMENTS);
groupParameters.Add(BuiltInParameterGroup.PG_COUPLER_ARRAY);
groupParameters.Add(BuiltInParameterGroup.PG_REBAR_ARRAY);
groupParameters.Add(BuiltInParameterGroup.PG_STRUCTURAL);
groupParameters.Add(BuiltInParameterGroup.PG_OVERALL_LEGEND);
groupParameters.Add(BuiltInParameterGroup.PG_GENERAL);
groupParameters.Add(BuiltInParameterGroup.PG_PRIMARY_END);
groupParameters.Add(BuiltInParameterGroup.PG_IFC);
groupParameters.Add(BuiltInParameterGroup.INVALID);
groupParameters.Add(BuiltInParameterGroup.PG_GEOMETRY);
groupParameters.Add(BuiltInParameterGroup.PG_STRUCTURAL_ANALYSIS);
groupParameters.Add(BuiltInParameterGroup.PG_ENERGY_ANALYSIS);
groupParameters.Add(BuiltInParameterGroup.PG_SLAB_SHAPE_EDIT);
groupParameters.Add(BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
groupParameters.Add(BuiltInParameterGroup.PG_PLUMBING);
groupParameters.Add(BuiltInParameterGroup.PG_ADSK_MODEL_PROPERTIES);
groupParameters.Add(BuiltInParameterGroup.PG_GREEN_BUILDING);
groupParameters.Add(BuiltInParameterGroup.PG_SEGMENTS_FITTINGS);
groupParameters.Add(BuiltInParameterGroup.PG_FORCES);
groupParameters.Add(BuiltInParameterGroup.PG_FIRE_PROTECTION);
groupParameters.Add(BuiltInParameterGroup.PG_REBAR_SYSTEM_LAYERS);
groupParameters.Add(BuiltInParameterGroup.PG_RELEASES_MEMBER_FORCES);
groupParameters.Add(BuiltInParameterGroup.PG_PHASING);
groupParameters.Add(BuiltInParameterGroup.PG_CONSTRUCTION);
groupParameters.Add(BuiltInParameterGroup.PG_TEXT);
groupParameters.Add(BuiltInParameterGroup.PG_LIGHT_PHOTOMETRICS);
groupParameters.Add(BuiltInParameterGroup.PG_TITLE);
groupParameters.Add(BuiltInParameterGroup.PG_ELECTRICAL_ENGINEERING);
groupParameters.Add(BuiltInParameterGroup.PG_ELECTRICAL);
groupParameters.Add(BuiltInParameterGroup.PG_ELECTRICAL_LOADS);
groupParameters.Add(BuiltInParameterGroup.PG_ELECTRICAL_LIGHTING);
groupParameters.Add(BuiltInParameterGroup.PG_ELECTRICAL_CIRCUITING);
return groupParameters;
}
Can't find what you're looking for? Ask the community or share your knowledge.