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