- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
I'm trying to split Duct by 2 points from user, but I can only split duct when the user pick point from left to right. If the user pick 2 points from right to left I will get the error. Can anyone help me fix that.
Thank you.
The following is my code:
using Autodesk.Revit.Attributes;
using Nice3point.Revit.Toolkit.External;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Mechanical;
namespace RevitAddIn2.Commands
{
/// <summary>
/// External command entry point invoked from the Revit interface
/// </summary>
[UsedImplicitly]
[Transaction(TransactionMode.Manual)]
public class DuctUpDownCmd : ExternalCommand
{
public override void Execute()
{
var ductRefer = UiDocument.Selection.PickObject(ObjectType.Element);
var ductElement = Document.GetElement(ductRefer);
var ductLocationCurve = ductElement.Location as LocationCurve;
var ductCurve = ductLocationCurve.Curve;
using (var tx = new Transaction(Document, "Break Duct"))
{
tx.Start();
var startRefPoint = UiDocument.Selection.PickObject(ObjectType.PointOnElement);
var insectStartPoint = ductCurve.Project(startRefPoint.GlobalPoint).XYZPoint;
var splitedDuctIdAtStartPoint = MechanicalUtils.BreakCurve(Document, ductRefer.ElementId, insectStartPoint);
var splitedDuctAtStartPoint = Document.GetElement(splitedDuctIdAtStartPoint);
var newDuctCurveLocation = splitedDuctAtStartPoint.Location as LocationCurve;
var newDuctCurve = newDuctCurveLocation.Curve;
var endRef = UiDocument.Selection.PickObject(ObjectType.PointOnElement);
var insectPtEnd = newDuctCurve.Project(endRef.GlobalPoint).XYZPoint;
var eleIdEnd = MechanicalUtils.BreakCurve(Document, splitedDuctIdAtStartPoint, insectPtEnd);
tx.Commit();
}
}
}
}
Solved! Go to Solution.