Wall: attach top/base, no API?

Wall: attach top/base, no API?

Anonymous
Not applicable
7,337 Views
28 Replies
Message 1 of 29

Wall: attach top/base, no API?

Anonymous
Not applicable

I searched around with no luck. So,  to create a gable wall, the only way is to work out the profile and vertices? 

Thanks in advance.

0 Likes
Accepted solutions (1)
7,338 Views
28 Replies
Replies (28)
Message 21 of 29

jorge.bustinza
Explorer
Explorer

jorgebustinza_0-1744715020346.png

Good morning
Are the Revit Interface commands (Attach Top/Base) exposed in the API?
Jorge Bustinza

0 Likes
Message 22 of 29

jeremy_tammik
Alumni
Alumni

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

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 23 of 29

jorge.bustinza
Explorer
Explorer

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();
         }
      }

 

0 Likes
Message 24 of 29

jeremy_tammik
Alumni
Alumni

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?

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 25 of 29

jorge.bustinza
Explorer
Explorer

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.

jorgebustinza_0-1744720798345.png

jorgebustinza_1-1744720855028.png

 

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.

0 Likes
Message 26 of 29

GaryOrrMBI
Collaborator
Collaborator

"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.

 

GaryOrrMBI_0-1744724176733.png

 

Hopefully this will help in understanding the relationships.

 

-G

 

 

 

 

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
Message 27 of 29

jorge.bustinza
Explorer
Explorer

jorgebustinza_0-1744728458394.png

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);
            }

 

0 Likes
Message 28 of 29

GaryOrrMBI
Collaborator
Collaborator

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

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes