Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active May 18, 2021 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/8ec824d9c0069aaf12704f2497f5fa37 to your computer and use it in GitHub Desktop.
Save chuongmep/8ec824d9c0069aaf12704f2497f5fa37 to your computer and use it in GitHub Desktop.
public static ModelCurve CreateModelLine(Document doc,
XYZ pmin,
XYZ pmax)
{
double _eps = 1.0e-9;
if (pmin.DistanceTo(pmax) < _eps) return null;
XYZ v = pmax - pmin;
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 tpmin = new XYZ(pmin.X,pmin.Y,0);
Plane plane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(norm, tpmin);
SketchPlane sketchPlane = Autodesk.Revit.DB.SketchPlane.Create(doc, plane);
//MessageBox.Show(tpmin+"\n"+pmax);
Line line = Line.CreateBound(tpmin, pmax);
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