Files
SzmediTools/GeologyToolkit/KrigingInsertCmd.cs
2025-09-16 16:06:41 +08:00

83 lines
2.9 KiB
C#

using System;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
using Nice3point.Revit.Toolkit.External;
namespace GeologyToolkit
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class KrigingInsertCmd : ExternalCommand
{
public override void Execute()
{
var e = UiDocument.Selection.PickObject(ObjectType.Element);
var originSurface = Document.GetElement(e) as TopographySurface;
var points = originSurface.GetPoints();
var xyPoints = points.Select(p => new XYPoint(p.X, p.Y) { Elevation = p.Z }).ToList();
var kriging = new KrigingMethod();
//List<XYPoint> xyPoints = new List<XYPoint>
//{
// new XYPoint(10, 0)
// {
// Elevation = 18.1
// },
// new XYPoint(0, 5)
// {
// Elevation = 15.5
// },
// new XYPoint(15, 15)
// {
// Elevation = 16.81
// },
// new XYPoint(8.1, 4.5)
// {
// Elevation = 16.73
// },
// new XYPoint(9.1, 7.5)
// {
// Elevation = 18.56
// }
//};
var random = new Random();
var x = random.NextDouble() * 20;
var y = random.NextDouble() * 20;
var xy = new XYPoint(x, y);
xy.Elevation = kriging.MainMethod(xyPoints, xy);
//List<XYZ> xyzList = new List<XYZ> { new XYZ(xy.X, xy.Y, xy.Elevation) };
points.Add(new XYZ(xy.X, xy.Y, xy.Elevation));
//using (Transaction trans = new Transaction(doc, "创建"))
//{
// trans.Start();
// using (TopographyEditScope scope = new TopographyEditScope(doc, "创建"))
// {
// scope.Start(originSurface.Id);
// originSurface.AddPoints(xyzList);
// scope.Commit(new GeologyFailureProcessor());
// }
// trans.Commit();
//}
//xyPoints.Add(xy);
//List<XYZ> xyzList = new List<XYZ>();
//foreach (var xyPoint in xyPoints)
//{
// XYZ p = new XYZ(xyPoint.X, xyPoint.Y, xyPoint.Elevation);
// xyzList.Add(p);
//}
using (var trans = new Transaction(Document, "创建"))
{
trans.Start();
var surface = TopographySurface.Create(Document, points);
trans.Commit();
}
}
}
}