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 );
Air Duct Movement
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
Reference: http://revit.haotui.com/thread-171-1-32.htmlhttp://revit.haotui.com/thread-489-1-23.html