Source
// about line in revit
public static void drawMline(ExternalCommandData commandData)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Autodesk.Revit.DB.Document doc = uidoc.Document;
XYZ p1 = new XYZ();
XYZ p2= p1.Add(new XYZ(5,5,0));
using (Transaction tr = new Transaction(doc, "MLINE"))
{
tr.Start();
CreateModelLine(doc, p1, p2);
tr.Commit();
}
}
public static void CreateModelLine( Autodesk.Revit.DB.Document doc,XYZ p, XYZ q)
{
if (p.Equals(q))
{
throw new ArgumentException(
"Expected two different points.");
}
Line line = Line.CreateBound(p, q); //_app.NewLine(p, q, true);
if (null == line)
{
throw new Exception(
"Geometry line creation failed.");
}
doc.Create.NewModelCurve(line,NewSketchPlanePassLine(doc,line));
}
public static SketchPlane NewSketchPlanePassLine(Autodesk.Revit.DB.Document doc, Line line)
{
XYZ p = line.GetEndPoint(0);
XYZ q = line.GetEndPoint(1);
XYZ norm;
if (p.X == q.X)
{
norm = XYZ.BasisX;
}
else if (p.Y == q.Y)
{
norm = XYZ.BasisY;
}
else
{
norm = XYZ.BasisZ;
}
Plane plane = doc.Application.Create.NewPlane(norm, p);
return SketchPlane.Create(doc, plane);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น