Message 1 of 3
How to create a simple wall using C# command?
Not applicable
12-25-2018
12:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello guys, I'm newbie for Revit API.
I was trying to learn create a simple wall for few hours and frustrated... 😛
The problem is my `symbolID` always -1 and created null reference symbol.
Please help me what is wrong with this code snippet?
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData command_data,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
var document = command_data.Application.ActiveUIDocument.Document;
var level_id = new ElementId(1526);
var wallTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType);
// create line
XYZ point_a = new XYZ(-10, 0, 0);
XYZ point_b = new XYZ(10, 10, 10);
Line line = Line.CreateUnbound(point_a, point_b);
using (var transaction = new Transaction(document))
{
transaction.Start("create walls");
Wall wall = Wall.Create(doc, arc, level_id, false);
var position = new XYZ(0, 0, 0);
var symbolId = document.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_Walls));
if (symbolId == ElementId.InvalidElementId) {
transaction.RollBack();
return Result.Failed;
}
var symbol = document.GetElement(symbolId) as FamilySymbol;
var level = (Level)document.GetElement(wall.LevelId);
document.Create.NewFamilyInstance(position, symbol, wall, level, StructuralType.NonStructural);
transaction.Commit();
}
return Result.Succeeded;
}