Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active May 18, 2021 17:57
Show Gist options
  • Save chuongmep/e846faf059eaf23df1a34f9871ec9430 to your computer and use it in GitHub Desktop.
Save chuongmep/e846faf059eaf23df1a34f9871ec9430 to your computer and use it in GitHub Desktop.
public static ModelCurve CreateModelLine(Document doc,
XYZ p,
XYZ q)
{
double _eps = 1.0e-9;
if (p.DistanceTo(q) < _eps) return null;
XYZ v = q - p;
double dxy = Math.Abs(v.X) + Math.Abs(v.Y);
XYZ w = (dxy > _eps)
? XYZ.BasisZ
: XYZ.BasisY;
XYZ norm = v.CrossProduct(w).Normalize();
XYZ temp = new XYZ(p.X,p.Y,0);
Plane plane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(norm, p);
//MessageBox.Show(plane.Origin.ToString());
SketchPlane sketchPlane = Autodesk.Revit.DB.SketchPlane.Create(doc, plane);
Line line = Line.CreateBound(p, q);
ModelCurve modelCurve = doc.Create.NewModelCurve(line, sketchPlane);
return modelCurve;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment