Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Template - Check if Template controls some field

1 REPLY 1
Reply
Message 1 of 2
Julian.Wandzilak
137 Views, 1 Reply

Template - Check if Template controls some field

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 😉 

blog: w7k.pl more about me: Linkedin Profile
My add-ins for Revit: Drafter(180+ scripts) & Leveler
Tags (2)
1 REPLY 1
Message 2 of 2
longt61
in reply to: Julian.Wandzilak

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.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community