Revit 2020 Window Function Type Parameter

Revit 2020 Window Function Type Parameter

Sean_Page
Collaborator Collaborator
735 Views
3 Replies
Message 1 of 4

Revit 2020 Window Function Type Parameter

Sean_Page
Collaborator
Collaborator

I have an application that loops nearly every model element in an attempt to set it to the correct Workset, but it is breaking in Revit 2020 when running against elements in the Window category. The error is when I try to retrieve the "Function" (BuiltInParameter.FUNCTION_PARAM) and it is returning a NullReferenceException. When I get into the model it appears that "Function" no longer a Type Parameter.

 

Would someone verify this parameter is in fact gone?

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Accepted solutions (2)
736 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

How about simply checking for null before dereferencing the parameter?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

Sean_Page
Collaborator
Collaborator

Yes, that would be  a perfect solution, especially had I actually read my code well enough to notice that I was checking the Function of the HOSTWALL and not the actual Window. My issue is NOT with the Window... apparently its with my Eyes!

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 4 of 4

Sean_Page
Collaborator
Collaborator
Accepted solution

Just so I circle back on this and close it up, here is what I ended up with, which was checking for the Null Host using an "is" statement once I realized it was a random Modeled In Place family of "Window" category throwing the exception.

 

foreach (Element window in Helpers.Collectors.ByCategoryNotElementType(doc, BuiltInCategory.OST_Windows))
                        {
                            method = "Windows";
                            if (!window.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).IsReadOnly)
                            {
                                elems++;
                                if (doc.GetElement(window.get_Parameter(BuiltInParameter.HOST_ID_PARAM).AsElementId()) is Wall hostWall)
                                {
                                    if (Helpers.Parameters.Tbip(doc, hostWall, BuiltInParameter.FUNCTION_PARAM).AsInteger() == 0)
                                    {
                                        window.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(Helpers.Worksets.WorksetIdByName(doc, "A-INTERIOR").IntegerValue);
                                    }
                                    else
                                    {
                                        window.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(Helpers.Worksets.WorksetIdByName(doc, "A-EXTERIOR").IntegerValue);
                                    }
                                }
                            }
                        }
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect