Hello,
I am trying to check if view template controls formatting of the columns in the selected schedule. And I have a problem, I am sure one of you will be able to help;)
ViewSchedule scheduleToBeChanged = doc.GetElement(scheduleSheetInstance.ScheduleId) as ViewSchedule;
//TODO : older versions
if (scheduleToBeChanged.ViewTemplateId.Value != -1)
{
//Autodesk.Revit.DB.Element template = doc.GetElement(scheduleToBeChanged.ViewTemplateId);
IEnumerable<Autodesk.Revit.DB.View> views = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.View)).Cast<Autodesk.Revit.DB.View>().Where(v => v.Id.Equals(scheduleToBeChanged.ViewTemplateId));
Autodesk.Revit.DB.View template = views.FirstOrDefault();
try
{
Autodesk.Revit.DB.Parameter Formatting = (template as ViewSchedule).get_Parameter(BuiltInParameter.SCHEDULE_FORMAT_PARAM);
My idea was to save a formatting parameter, Get its ID and check against :
ICollection<ElementId> paramsId = (template as Autodesk.Revit.DB.View).GetTemplateParameterIds();
ICollection<ElementId> paramsId2 = (template as Autodesk.Revit.DB.View).GetNonControlledTemplateParameterIds();
if (paramsId.Contains(Formatting.Id))
{
TaskDialog.Show("TEST", "Param in GetTemplateParameterIds");
}
if (paramsId2.Contains(Formatting.Id))
{
TaskDialog.Show("TEST", "Param in GetNonControlledTemplateParameterIds");
}
I don't know why, but when I try to get the parameter, I end up with "Object reference not set to an instance of an object." Any idea what I do wrong / or what should I study 😉
It is quite obvious that the schedule view does not have a template. Therefore, you can not get the controlled parameter Ids from it. You should always check if the ViewTemplateId is different from null and ElementId.Invalid to see whether the selected schedule view has a template or not.
P/s: In line 6 from the first snippet of code, you can cast it to Vew instead of trying to compare the view Id to all the existing view in current document.
Can't find what you're looking for? Ask the community or share your knowledge.