Files
ShrlAlgoToolkit/RvAddinTest/CorrectSlope.cs
2024-12-22 10:26:12 +08:00

58 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External;
using Nice3point.Revit.Toolkit.Utils;
using Sai.Toolkit.Revit.Assist;
namespace RvAddinTest;
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
internal class CorrectSlope : ExternalCommand
{
public override void Execute()
{
var ids = UiDocument.Selection.GetElementIds();
Document.Modify(
set => set.Transaction).Commit((doc, t) =>
{
foreach (var id in ids)
{
var elem = Document.GetElement(id);
if (elem is MEPCurve mep)
{
var loc = mep.GetCurve() as Line;
var x = Math.Round(loc.Direction.X);
var y = Math.Round(loc.Direction.Y);
var z = Math.Round(loc.Direction.Z);
//if (Math.Abs(x) < 10E-5)
//{
// x = 0;
//}
//if (Math.Abs(y) < 10E-5)
//{
// y = 0;
//}
//if (Math.Abs(z) < 10E-5)
//{
// z = 0;
//}
var dir = new XYZ(x, y, z);
var endPoint = loc.Origin + dir * loc.Length;
var li = Line.CreateBound(loc.Origin, endPoint);
var locx = mep.GetLocationCurve();
locx.Curve = li;
}
}
});
}
}