start
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
cmdDuctAlign : IExternalCommand
{
XYZ GetIntersection(Line line1, Line line2)
{
IntersectionResultArray results;
SetComparisonResult result
= line1.Intersect(line2, results);
(SetComparisonResult.Overlap == result) InvalidOperationException(
);
(SetComparisonResult.Disjoint == result) InvalidOperationException(
);
(SetComparisonResult.Superset == result) InvalidOperationException(
);
(SetComparisonResult.Subset == result) InvalidOperationException(
);
(results == || results.Size != )
InvalidOperationException(
);
IntersectionResult iResult
= results.get_Item();
iResult.XYZPoint;
}
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
SplitButtonData splitButtonData = SplitButtonData(, );
PushButton pbtn = PushButton();
RibbonPanel rpanel = RibbonPanel();
Transaction ts = Transaction(doc, );
ts.Start();
IList<Reference> refDucts = sel.PickObjects(ObjectType.Element, );
Duct duct1 = doc.GetElement(refDucts.ElementAt()) Duct;
Duct duct2 = doc.GetElement(refDucts.ElementAt()) Duct;
LocationCurve lCurve1 = duct1.Location LocationCurve;
LocationCurve lCurve2 = duct1.Location LocationCurve;
XYZ xyz11 = lCurve1.Curve.get_EndPoint();
XYZ xyz12 = lCurve1.Curve.get_EndPoint();
XYZ xyz21 = lCurve2.Curve.get_EndPoint();
XYZ xyz22 = lCurve2.Curve.get_EndPoint();
Line line1 = Line.get_Bound(xyz11, xyz12);
Line line2 = Line.get_Bound(xyz21, xyz22);
GetIntersection(line1, line2);
風管移動
XYZ xyz1 = XYZ(xyz11.X, xyz11.Y, );
XYZ xyz2 = XYZ(xyz12.X, xyz12.Y, );
XYZ xyz3 = XYZ(xyz21.X, xyz21.Y, );
XYZ xyz4 = XYZ(xyz22.X, xyz22.Y, );
XYZ vec1 = xyz2 - xyz1;
XYZ zVec = XYZ(, , );
XYZ nVec = vec1.CrossProduct(zVec).Normalize(); TaskDialog.Show(, nVec.CrossProduct(zVec).Normalize().ToString());
lCurve2.Move(nVec);
ts.Commit();
Result.Succeeded;
}
}url: http://greatverve.cnblogs.com/p/revit-api-line-SetComparisonResult.html
參考:http://revit.haotui.com/thread-171-1-32.htmlhttp://revit.haotui.com/thread-489-1-23.html