- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to create a non-rectangular wall. This code uses 3 points to define 3 lines. But the wall that Revit creates does not match the lines. What is wrong?
public void walltest()
{
Document doc = this.ActiveUIDocument.Document;
// create points
List<XYZ> pts = new List<XYZ>();
XYZ first = new XYZ(0, 0, 20);
XYZ second = new XYZ(20, 0, 35);
XYZ third = new XYZ(30, 0, 55);
// create curves connecting these points
IList<Curve> profile = new List<Curve>();
profile.Add(Line.CreateBound(first, second));
profile.Add(Line.CreateBound(second, third));
profile.Add(Line.CreateBound(third, first));
// create model lines for each line (for diagnostics)
foreach (Curve line in profile)
{
makeModelLine(doc, (Line)line);
}
// create wall;
using (Transaction t = new Transaction(doc, "test"))
{
t.Start();
Wall.Create(doc, profile, false);
t.Commit();
}
}
// helper functions to create model lines
public static ModelLine makeModelLine(Document doc, Line line)
{
if (line == null)
return null;
return makeLine(doc, line.GetEndPoint(0), line.GetEndPoint(1));
}
public static ModelLine makeLine(Document doc, XYZ pt1, XYZ pt2)
{
if (pt1 == null || pt2 == null)
return null;
ModelLine ret = null;
using (Transaction t = new Transaction(doc, "g"))
{
bool started = false;
try
{
t.Start();
started = true;
}
catch
{ }
ret = (ModelLine)doc.Create.NewModelCurve(Line.CreateBound(pt1, pt2), SketchPlane.Create(doc, makePlane(doc.Application, pt1, pt2)));
if (started)
t.Commit();
}
return ret;
}
private static Plane makePlane(Autodesk.Revit.ApplicationServices.Application app, XYZ pt1, XYZ pt2)
{
XYZ v = pt1.Subtract(pt2);
double dxy = Math.Abs(v.X) + Math.Abs(v.Y);
XYZ w = (dxy > 0.0001) ? XYZ.BasisZ : XYZ.BasisY;
XYZ norm = v.CrossProduct(w).Normalize();
return app.Create.NewPlane(norm, pt1);
}
Solved! Go to Solution.