Start
[Transaction (TransactionMode. Manual)]
[Regeneration (RegenerationOption. Manual)]
Cmd: IExternalCommand
{
List <Connector> getConn (Duct duct)
{
List <Connector> listConn = List <Connector> ();
ConnectorSetIterator csi = duct. ConnectorManager. Connectors. ForwardIterator ();
(Csi. MoveNext ())
{
Connector conn = csi. Current Connector;
(ConnectorType. End = conn. ConnectorType)
{
ListConn. Add (conn );
}
(ConnectorType. Curve = conn. ConnectorType)
{
}
}
ListConn;
}
Result Execute (ExternalCommandData upload data, msg, ElementSet elements)
{
UIDocument uiDoc = upload data. Application. ActiveUIDocument;
UIApplication uiApp = response data. Application;
Document doc = uiDoc. Document;
Selection sel = uiDoc. Selection;
Transaction ts = Transaction (doc ,);
Ts. Start ();
{
Element elDuct0 = doc. GetElement (sel. PickObject (ObjectType. Element ,));
Element elDuct1 = doc. GetElement (sel. PickObject (ObjectType. Element ,));
Duct duct0 = elDuct0 Duct;
Duct duct1 = elDuct1 Duct;
List <Connector> listConn0 = getConn (duct0 );
List <Connector> listConn1 = getConn (duct1 );
Line line0 = Line. get_Bound (listConn0 []. Origin, listConn0 []. Origin );
Line line1 = Line. get_Bound (listConn1 []. Origin, listConn1 []. Origin );
DDis = line1.Distance (line0.get _ EndPoint (); XYZ xyzVector = GetXYVector (line0, line1 );
LocationCurve lc = elDuct1.Location LocationCurve;
Lc. Move (dDis * xyzVector );
Ts. Commit ();
}
(Autodesk. Revit. Exceptions. OperationCanceledException)
{
Ts. RollBack ();
Result. Cancelled;
}
(Exception ex)
{
Ts. RollBack ();
}
Result. Succeeded;
}
XYZ GetXYVector (Line line0, Line line1)
{
XYZ startPoint0 = line0.get _ EndPoint ();
XYZ endPoint0 = line0.get _ EndPoint ();
XYZ startPoint1 = line1.get _ EndPoint ();
XYZ endPoint1 = line1.get _ EndPoint ();
XYZ resultVector = XYZ (,,);
XYZ zStart = XYZ (startPoint1.X, startPoint1.Y ,);
XYZ zEnd = XYZ (endPoint1.X, endPoint1.Y ,);
Line line = Line. get_Bound (XYZ (startPoint0.X, startPoint0.Y,), XYZ (endPoint0.X, endPoint0.Y ,));
Line. MakeUnbound ();
XYZ tPoint = zStart-zEnd;
XYZ zVector = XYZ (,,);
XYZ nPoint = tPoint. CrossProduct (zVector). Normalize () + zStart;
Line lineN = Line. get_Bound (zStart, nPoint );
LineN. MakeUnbound ();
IntersectionResultArray intersectionR = IntersectionResultArray ();
SetComparisonResult comparisonR;
ComparisonR = line. Intersect (lineN, intersectionR );
(SetComparisonResult. Disjoint! = ComparisonR)
{
(! IntersectionR. IsEmpty)
{
ResultVector = intersectionR. get_Item (). XYZPoint;
}
}
(! ZStart. IsAlmostEqualTo (resultVector ))
{
ResultVector = (resultVector-zStart). Normalize ();
}
ResultVector;
}
}