调整代码
This commit is contained in:
79
ShrlAlgoToolkit.RevitAddins/Mep/BreakMEPCurveCmd.cs
Normal file
79
ShrlAlgoToolkit.RevitAddins/Mep/BreakMEPCurveCmd.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Windows;
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Mechanical;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.RvMEP;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Mep;
|
||||
|
||||
/// <summary>
|
||||
/// Revit执行命令
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class BreakMEPCurveCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var filter1 = new FuncFilter(
|
||||
e => e is MEPCurve and not InsulationLiningBase and not FlexDuct and not FlexPipe);
|
||||
var refer1 = UiDocument.Selection.PickObject(
|
||||
ObjectType.PointOnElement, filter1
|
||||
, "拾取打断管线的位置");
|
||||
var pointPicked = refer1.GlobalPoint;
|
||||
|
||||
var mepCurve = UiDocument.Document.GetElement(refer1) as MEPCurve;
|
||||
var loc = mepCurve.GetCurve() as Line;
|
||||
var d = loc.Direction;
|
||||
var halfGap = 20 / 304.8;
|
||||
var point1 = pointPicked - d * halfGap;
|
||||
var point2 = pointPicked + d * halfGap;
|
||||
|
||||
var breakPoint1 = mepCurve.GetCurve().Project(point1).XYZPoint;
|
||||
var breakPoint2 = mepCurve.GetCurve().Project(point2).XYZPoint;
|
||||
if (!loc.IsInsideEx(breakPoint1, halfGap) || !loc.IsInsideEx(breakPoint2, halfGap))
|
||||
{
|
||||
MessageBox.Show("打断点距离管线端点太近");
|
||||
continue;
|
||||
}
|
||||
//var direction = breakPoint2 - breakPoint1;
|
||||
//var flag = direction.Normalize().IsAlmostEqualTo(loc.Direction);
|
||||
|
||||
Document.Invoke(_ =>
|
||||
{
|
||||
var second = mepCurve.BreakByPoint(breakPoint1);
|
||||
var third = mepCurve.BreakByPoint(breakPoint2);
|
||||
Document.Delete(third);
|
||||
|
||||
//if (flag)
|
||||
//{
|
||||
// var second = mepCurve.BreakByPoint(breakPoint1);
|
||||
// var third = mepCurve.BreakByPoint(breakPoint2);
|
||||
// Document.Delete(third);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// var second = mepCurve.BreakByPoint(breakPoint2);
|
||||
// //var mepCurve2 = Document.GetElement(second) as ElementToMove;
|
||||
// var third = mepCurve.BreakByPoint(breakPoint1);
|
||||
// Document.Delete(third);
|
||||
|
||||
//}
|
||||
|
||||
}, "打断管线");
|
||||
}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user