Creating Wall Problem

Creating Wall Problem

Anonymous
Not applicable
610 Views
1 Reply
Message 1 of 2

Creating Wall Problem

Anonymous
Not applicable

Hi. I'm new in Revit API.

I wanna create walls on some levels that i set the elevation at levels. 

But there is a distance between walls.

I think the elevation is the cause.

How can i fix it?

Here is my code.

[TransactionAttribute(TransactionMode.Manual)]
public class CreateHome : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;

//Get Document
Document doc = uidoc.Document;

//
XYZ p1 = new XYZ(-10, -10, 60);
XYZ p2 = new XYZ(10, -10, 60);
XYZ p3 = new XYZ(15, 0, 60);
XYZ p4 = new XYZ(10, 10, 60);
CurveArray lineList = new CurveArray();
List<Curve> curves = new List<Curve>();
Line line1 = Line.CreateBound(p1, p2);
Line line2 = Line.CreateBound(p2, p3);
Line line3 = Line.CreateBound(p3, p4);
Line line4 = Line.CreateBound(p4, p1);
lineList.Append(line1);
lineList.Append(line2);
lineList.Append(line3);
lineList.Append(line4);

curves.Add(line1);
curves.Add(line2);
curves.Add(line3);
curves.Add(line4);


XYZ normal = XYZ.BasisZ;
FilteredElementCollector Beamsymbolcol = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(FloorType));
FloorType ft = null;
foreach (FloorType fs1 in Beamsymbolcol)
{
ft = fs1;
break;
}
try
{
using (Transaction trans = new Transaction(doc, "Place Family"))
{
trans.Start();
int cnt = 1;

double elevation = 0;
for(int i =1; i<=4;i++)
{

string levelName = "Level " + i;

elevation += 20;
Level level = Level.Create(doc, elevation);
level.Name = "Level " + i;

 


if (null == level)
{
throw new Exception("Create a new level failed.");
}
cnt += 20;
// Change the level name
}
//Level level1 = new FilteredElementCollector(doc)
// .OfCategory(BuiltInCategory.OST_Levels)
// .WhereElementIsNotElementType()
// .Cast<Level>()
// .First(x => x.Name == "Level 1");

FilteredElementCollector levels = new FilteredElementCollector(doc).OfClass(typeof(Level));
foreach (Level level in levels)
{
Floor newFloor = doc.Create.NewFloor(lineList, ft, level, false, normal);
foreach(Curve c in curves)
{

Wall.Create(doc, c, level.Id, false);
}
newFloor.get_Parameter(
BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0);
}

//Floor floor = doc.Create.NewFloor(lineList, ft, level1, false, normal);
trans.Commit();
}

0 Likes
Accepted solutions (1)
611 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk
Accepted solution

Welcome to the Revit API!

 

Please work through the Revit API getting started material first, before doing anything else:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That will address this issue of yours and all other fundamentals as well.

 

Good luck and have fun!

 

Cheers,

 

Jeremy

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder