Normally, when you create a wall, the level id that you specify determines its lower bound. You can set the upper bounding level using the built-in parameter BuiltInParameter.WALL_HEIGHT_TYPE, cf., the little house sample in the ADN Labs:
https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs
In our project, we need the base of all walls to be a reference plane, which forms a 3% slope with the Revit levels.
In the attached code, I'm trying to set the ID of these two reference planes (top and bottom) to the Top Constraint and Base Constraint parameters for each wall. But this option is incorrect, it doesn't work.
How can I use the API to perform the action performed in the Revit interface with Top Attach? This new action was recently added.
private void Module_Startup(object? sender, EventArgs e)
{
Autodesk.Revit.ApplicationServices.Application rvtApp = this.Application;
Document doc = this.ActiveUIDocument.Document;
ReferencePlane refPlaneInf = null;
ReferencePlane refPlaneSup = null;
List<Element> listWalls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToList();
List<Element> listElements = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_CLines).WhereElementIsNotElementType().ToList();
// Search for the upper and lower reference planes
foreach( Element el in listElements)
{
if (el.Name =="RefPlaneInf") refPlaneInf = el as ReferencePlane;
if (el.Name =="RefPlaneSup") refPlaneSup = el as ReferencePlane;
}
using (Transaction tx = new Transaction(doc))
{
tx.Start("Find ReferencePlane");
// The Id of the Reference Plane is passed to the Top Constraint parameter
foreach (Wall wall in listWalls)
{
Parameter p = wall.get_Parameter( BuiltInParameter.WALL_HEIGHT_TYPE ); // Top Constraint
p.Set(refPlaneSup.Id);
p = wall.get_Parameter( BuiltInParameter.WALL_BASE_CONSTRAINT ); // Base Constraint
p.Set(refPlaneInf.Id);
}
tx.Commit();
}
}
I think that the WALL_BASE_CONSTRAINT is intended to be used with level objects, so that may not work. Please research that further and confirm. So, you may need to construct a different type of wall and implement a generic constrant locking its bottom face to the reference plane. How exactly do you achieve your desired model manually in the UI?
As you indicate, the TopConstraint and BaseConstraint parameters require a Level ID.
Our project is a large building where the Project Manager has imposed a requirement to model based on reality, which means the reference plane cannot be a Revit level.
There is an option in the Revit Interface that activates when selecting a set of walls that allows you to assign a specific Reference Plane to each wall, either at the top or bottom. This option is slow and tedious for modelers, but thank goodness, because it didn't even exist before.
What we're looking for a way to automate this process, hoping that these new Interface Tools will also be exposed in the API.
"How can I use the API to perform the action performed in the Revit interface with Top Attach? This new action was recently added."
This ability has been added to the 2026 API with the method "AddAttachment" (and associated methods for "GetAttachments", "IsValidTargetAttachment", "RemoveAttachment").
"Wall.AddAttachment Method
Attaches the wall to the target. If an attachment alreadyexists with the same "attachmentLocation" value, an exception is thrown. The target should be a roof, floor, ceiling, toposolid, or other wall."
It does not mention reference planes as a possible target, yet you can use them in the UI so that could be an oversight and it would be worth trying it.
On to other matters. Your code is trying to set the Base and Top constraints. These constraints are not the same as having an attachment.
The constraints are always a level (or unconstrained as an option for the top). You can then set positive or negative offset values relative to those constraints (or a fixed height in the case of no assigned Top Constraint).
Top and/or Base constraints are then ignored when generating the geometry after attaching either to other geometry or after editing the wall profile.
Hopefully this will help in understanding the relationships.
-G
As you point out, it does not work with ReferencePlane.
This code does not work, does not recognize the ID of the reference planes:
foreach (Wall wall in listWalls)
{
wall.AddAttachment(refPlaneSup.Id,AttachmentLocation.Top);
wall.AddAttachment(refPlaneInf.Id,AttachmentLocation.Base);
}
Unfortunately this is pretty typical with Revit (UI and API)... new features are added, but they usually take several releases to end up getting them to cover many real world scenarios.
The other limitation in this API function is that it is possible to attach the top or bottom to multiple elements in the UI (a wall to two or more roofs or floors for "stair stepping" type of uses, but the API help seems to indicate that you can only attach a single element to the top (or to the bottom) or it will throw an exception...
-G