Using some of the overloads of the Wall.Create method, the wall seems to be always placed between two existing levels. It seems the lowermost and the topmost line(s) of the created walls profile always have the same Z-value as the corresponding existing levels, even though the Wall profile contained different values of Z – coordinates. How can we create a wall, that uses the profile given for wall creating and not use the Z-values of existing levels.
It does seem that using the specific Wall.Create(Document, IList<Curve>, Boolean), overload of the Wall.Create() creates a wall (with sloping upper faces, as in this case) to be aligned to existing levels. After some initial investigation, for the given requirement to create a wall which is not automatically aligned to the Z-coordinate of existing Levels, we need to use the following approach:
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
using (Transaction trans = new Transaction(doc, "wall"))
{
trans.Start();
XYZ[] pts = new XYZ[] {
XYZ.Zero,
new XYZ( 5, 0, 12 ),
new XYZ( 10, 0, 0 ),
};
XYZ normal = XYZ.BasisY;
WallType wallType
= new FilteredElementCollector(doc)
.OfClass(typeof(WallType))
.First<Element>()
as WallType;
Level level
= new FilteredElementCollector(doc)
.OfClass(typeof(Level))
.First<Element>(e
=> e.Name.Equals("Level 1"))
as Level;
// Create wall profile
IList<Curve> profile = new List<Curve>();
XYZ q = pts[pts.Length - 1];
foreach (XYZ p in pts)
{
profile.Add(app.Application.Create.NewLineBound(
q, p));
q = p;
}
Wall wall = Wall.Create(doc, profile, wallType.Id, level.Id, true);
trans.Commit();
}
return Result.Succeeded;
}
}
Executing the above code creates the wall which has coordinates determined by its profile.