111 lines
4.1 KiB
C#
111 lines
4.1 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 点测试
|
|
/// </summary>
|
|
/// <param name="x"></param>
|
|
/// <param name="doc"></param>
|
|
/// <param name="isInTransaction"></param>
|
|
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();
|
|
}
|
|
/// <summary>
|
|
/// 测试线
|
|
/// </summary>
|
|
/// <param name="l"></param>
|
|
/// <param name="doc"></param>
|
|
/// <param name="isInTransaction"></param>
|
|
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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 线集合测试
|
|
/// </summary>
|
|
/// <param name="lines"></param>
|
|
/// <param name="doc"></param>
|
|
/// <returns></returns>
|
|
public static List<ModelCurve> lineListText(this List<Line> lines, Document doc)
|
|
{
|
|
List<ModelCurve> curves = new List<ModelCurve>();
|
|
foreach (var l in lines)
|
|
{
|
|
ModelCurve mc = l.LineTest(doc);
|
|
curves.Add(mc);
|
|
}
|
|
return curves;
|
|
}
|
|
/// <summary>
|
|
/// 几何体测试
|
|
/// </summary>
|
|
/// <param name="solid"></param>
|
|
/// <param name="doc"></param>
|
|
/// <param name="b"></param>
|
|
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<GeometryObject>() { solid });
|
|
}
|
|
transCreate?.Commit();
|
|
|
|
}
|
|
}
|
|
}
|