Question

I'm trying to get the wall brutto area with Revit API. However the only thing I'm getting is the netto area.

I'm using the method with deleting the wall and reverting the changes to determine all the elements that are placed on the wall. Then, I'm removing the wall's id from the ElementSet getting the value of HOST_AREA_COMPUTED in a variable and reverting the changes again. The result, however, is the wall netto area :( Does the parameter or wall needs any kind of reload? Or maybe there's easier way to get the brutto area? Any help would be appreciated as I can't find anything related to that problem. Thanks in advance!

        foreach (Wall wallElem in elems)
        {
            try
            {
                Double brutto = 0.0;
                ICollection<ElementId> delIds = null;

                using (SubTransaction t = new SubTransaction(doc))
                {
                    try
                    {
                        t.Start();

                        delIds = doc.Delete(wallElem);

                        t.RollBack();

                    }
                    catch (Exception ex)
                    {
                        message = "Deletion failed: " + ex.Message;
                        t.RollBack();
                    }
                }

                using (SubTransaction u = new SubTransaction(doc))
                {
                    try
                    {
                        u.Start();

                        delIds.Remove(wallElem.Id);
                        doc.Delete(delIds);
                        brutto = wallElem.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
                        u.RollBack();
                    }
                    catch (Exception ex)
                    {
                        message = "Deletion failed: " + ex.Message;
                        u.RollBack();
                    }
                }
                wallElem.get_Parameter("Wall Area Bruto").Set(brutto);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Was it helpful?

Solution

You're on the right track. I would suggest that after you delete the hosted elements, that you need to regenerate before the parameters for the wall will be updated.

Try:

doc.Delete(delIds);
doc.Regenerate();  // regenerate to cascade all changes.
wallElem = doc.get_Element(wallElem.Id);
brutto = wallElem.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();

If this doesn't work, then I would say your next step would be to try committing the subtransaction. After the subtransaction completes, you may be able to retrieve the brutto wall area, and then Rollback() the outside transaction.

OTHER TIPS

Have you tried just looking at the geometry? If you take the walls solid and look through the faces, there should be two faces that are way bigger than all the other faces and have a zero z component for their orientation - the area of one of these faces should be your brutto area!

BUT: specific to your question, you might try to re-fetch the wall element from the document:

delIds.Remove(wallElem.Id);
doc.Delete(delIds);
wallElem = doc.get_ElementById(wallElem.Id); // re-fetch wall element from BIM model
brutto = wallElem.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
u.RollBack();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top