Snap to nearest right angle breaks connectivity, "Family is connected.." error

Snap to nearest right angle breaks connectivity, "Family is connected.." error

Anonymous
Not applicable
698 Views
1 Reply
Message 1 of 2

Snap to nearest right angle breaks connectivity, "Family is connected.." error

Anonymous
Not applicable

Hello everyone,

 

I am trying to create an add-in that would allow me to have a selected pipe snap to the nearest 90 degree point.  Presently, the pipes appear to be snapping into place, based on the nearest base(right) angle and the connector adjusts graphically, but not without breaking connectivity and displaying a “Family is connected in a network and can no longer keep the connectivity” error.

 

Manually adjusting a pipe by dragging one end in the Revit UI does not cause any problems and so there is something else I am missing. Any input would be appreciated.

 

Thank you,

Charlton

 

CODE:

 

usingAutodesk.Revit.UI;

usingAutodesk.Revit.DB;

usingAutodesk.Revit.UI.Selection;

usingAutodesk.Revit.Attributes;

usingAutodesk.Revit.DB.Plumbing;

usingSystem.Collections.Generic;

usingSystem;

usingSystem.Linq;

namespaceVerticalPipes

{

    [TransactionAttribute(TransactionMode.Manual)]

    [RegenerationAttribute(RegenerationOption.Manual)]

    publicclassVerticalPipes : IExternalCommand

    {

        privateconstdoubleANGLE_TOLERANCE=Math.PI/4;   

        //private const double ANGLE_TOLERANCE = 9999;       

 

        publicResultExecute(ExternalCommandDatacommandData, refstringmessage, ElementSetelements)

        {

 

            UIApplicationuiApp=commandData.Application;

            Documentdoc=uiApp.ActiveUIDocument.Document;

 

            UIDocumentuidoc=newUIDocument(doc);

            Selectionchoices=uidoc.Selection;

            IEnumerable<Element>SelectedElements=null;

 

            if (!choices.Elements.Cast<Element>().Any(elem=> (elemisPipe) ||

                (elem.Category.Name.Contains("Pipe"))))

            {

 

                try

                {

                    SelectedElements=choices.PickObjects(ObjectType.Element, newElementIsPipeSelectionFilter(),"Select Pipes to rotate").Select(a=>doc.GetElement(a.ElementId));                   

 

                }

                catch(Autodesk.Revit.Exceptions.OperationCanceledExceptione)

                {

 

                    returnAutodesk.Revit.UI.Result.Cancelled;

 

                }

             

            }

            else

                SelectedElements=choices.GetElementIds().Select(a=>doc.GetElement(a));

            if (SelectedElements==null) returnAutodesk.Revit.UI.Result.Cancelled;;

            Transactiontrans=newTransaction(doc);

            trans.Start("Align");

            foreach (ElementeleinSelectedElements)

            {

               

                LocationCurvepipeLocation=ele.LocationasLocationCurve;

                if (pipeLocation==null)

                {

                    continue;

                }

                else

                {

                    varpoint1=pipeLocation.Curve.GetEndPoint(0);                   

                    XYZpoint2=pipeLocation.Curve.GetEndPoint(1);                   

                    varangle=Math.Atan2(point2.Y-point1.Y, point2.X-point1.X);

                    double []baseAngle=newdouble[]{0, Math.PI/2, Math.PI, Math.PI*1.5, Math.PI*2};                 

                    doubledistance=0;

                    doubleminAngle=double.MaxValue;

                    intminIndex=0;

 

                    for(inti=0; i<5; i++){

                        distance=Math.Abs(angle-baseAngle[i]);

                        if (distance<minAngle)

                        {

                            minAngle=distance;

                            minIndex=i;

                        }

                    }

                    if (minAngle<ANGLE_TOLERANCE)

                    {

                        varpoint=newXYZ(point1.X+pipeLocation.Curve.Length*Math.Cos(baseAngle[minIndex]), point1.Y+pipeLocation.Curve.Length*Math.Sin(baseAngle[minIndex]), point2.Z);

                        pipeLocation.Curve=Line.CreateBound(point1, point);

                    }

             

                }

            }

            trans.Commit();

            returnResult.Succeeded;

        }

    }

}

 

 

 

namespaceVerticalPipes

{

   

    classElementIsPipeSelectionFilter : Autodesk.Revit.UI.Selection.ISelectionFilter

    {

        publicboolAllowElement(Autodesk.Revit.DB.Elementelem)

        {

            return ((elemisPipe) ||

                (elem.Category.Name.Contains("Pipe")));

 

        }

 

        publicboolAllowReference(Autodesk.Revit.DB.Referencereference, Autodesk.Revit.DB.XYZposition)

        {

            returnfalse;

        }

    }

 

}

0 Likes
699 Views
1 Reply
Reply (1)
Message 2 of 2

ollikat
Collaborator
Collaborator

Hi

 

Actually I haven't never even tried to move pipes etc. like that...I mean using location curve. But as you noticed, it is not that straight forward via API as it is with UI.

 

I would suggest to deal with the pipe connectors and try moving them. I think you need to move the neighbour connector as well if the connector you move is connected (otherwise the connection probably is lost). If all related connectors are moved correctly, I think the network doesn't break after the command.