using Autodesk.Revit.DB; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GraphicsStudy { public static class TestMethod { /// /// 点测试 /// /// /// /// public static void XYZTest(this XYZ x, Document doc) { Autodesk.Revit.DB.Line l = Autodesk.Revit.DB.Line.CreateBound(x, new XYZ(x.X, x.Y + 100, x.Z)); XYZ basicZ = XYZ.BasisZ; if (l.Direction.AngleTo(XYZ.BasisZ) < 0.0001 || l.Direction.AngleTo(-XYZ.BasisZ) < 0.0001) basicZ = XYZ.BasisY; XYZ normal = basicZ.CrossProduct(l.Direction).Normalize(); Plane pl = Plane.CreateByNormalAndOrigin(normal, l.GetEndPoint(0)); Transaction transCreate = null; if (!doc.IsModifiable) transCreate = new Transaction(doc, "模型线测试"); transCreate?.Start(); SketchPlane sktpl = SketchPlane.Create(doc, pl); ModelCurve mc = doc.Create.NewModelCurve(l, sktpl); transCreate?.Commit(); } /// /// 测试线 /// /// /// /// public static ModelCurve LineTest(this Line l, Document doc) { XYZ basicZ = XYZ.BasisZ; if (l.Direction.AngleTo(XYZ.BasisZ) < 0.0001 || l.Direction.AngleTo(-XYZ.BasisZ) < 0.0001) basicZ = XYZ.BasisY; XYZ normal = basicZ.CrossProduct(l.Direction).Normalize(); Plane pl = Plane.CreateByNormalAndOrigin(normal, l.GetEndPoint(0)); Transaction transCreate = null; if (!doc.IsModifiable) transCreate = new Transaction(doc, "模型线测试"); transCreate?.Start(); SketchPlane sktpl = SketchPlane.Create(doc, pl); ModelCurve mc = doc.Create.NewModelCurve(l, sktpl); transCreate?.Commit(); return mc; } public static ModelCurve ArcTest(this Arc arc, Document doc) { //16 //Plane plane = new Plane(arc.Normal, arc.Center); //17-20 Plane plane = Plane.CreateByNormalAndOrigin(arc.Normal, arc.Center); Transaction transCreate = null; if (!doc.IsModifiable) transCreate = new Transaction(doc, "模型线测试"); transCreate?.Start(); SketchPlane sktpl = SketchPlane.Create(doc, plane); ModelCurve mc = doc.Create.NewModelCurve(arc, sktpl); transCreate?.Commit(); return mc; } /// /// 线集合测试 /// /// /// /// public static List lineListText(this List lines, Document doc) { List curves = new List(); foreach (var l in lines) { ModelCurve mc = l.LineTest(doc); curves.Add(mc); } return curves; } /// /// 几何体测试 /// /// /// /// public static void SolidText(this Solid solid, Document doc) { Transaction transCreate = null; if (!doc.IsModifiable) transCreate = new Transaction(doc, "模型线测试"); transCreate?.Start(); DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Mass)); if (ds != null) { ds.AppendShape(new List() { solid }); } transCreate?.Commit(); } } }