Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error inserting a tee using RoutingPreferenceManager

2 REPLIES 2
Reply
Message 1 of 3
reylorente1
179 Views, 2 Replies

Error inserting a tee using RoutingPreferenceManager

Estoy investiagnado el uso de RoutingPreferenceManager,y creando una nueva regla para insertar una tee.
Cree tres lineas.donde convergen en un punto,las convertir en tuberia,pero cuando voy a insertar la Tee,me da error.
Como pueden observar en el codigo,cambie,la posicion de los conectores ,pero me sigue dando error.aunque los puntos de origen,de las tuberia estas bien.
Que seria mi error?

 

I'm investigating using RoutingPreferenceManager, and creating a new rule to insert a tee.
Create three lines where they converge at a point, convert them into pipes, but when I go to insert the Tee, I get an error.
As you can see in the code, I changed the position of the connectors, but it still gives me an error, although the points of origin of the pipes are fine.
What would be my mistake?

 

#region Obtener una lista de tuberia
/// <summary>
/// Obtener una lista de tuberia
/// </summary>
/// <param name="uidoc"></param>
/// <returns></returns>
public List<Element> GetPipeLine(UIDocument uidoc)
{
    Document doc = uidoc.Document;
    ISelectionFilter selectionFilter = new PlanarFaceSelectionFilter(doc);
    IList<Reference> refer = uidoc.Selection.PickObjects(ObjectType.Element, selectionFilter, "Select mulitple planar faces");
    List<Element> elementlist = new List<Element>();

    foreach (Reference reference in refer)
    {
        Element elem = doc.GetElement(reference);
        elementlist.Add(elem);
    }
    return elementlist;
}
#endregion


#region Creacion de tuberia y la Tee
/// <summary>
/// Creacion de Tuberia
/// </summary>
/// <param name="uidoc"></param>
/// <param name="elementlist"></param>
public void CreatePipe(UIDocument uidoc, List<Element> elementlist)
{
    Document doc = uidoc.Document;
    //Get PipeType
    PipeType pipeType = new FilteredElementCollector(doc).OfClass(typeof(PipeType)).FirstElement() as PipeType;
    //Get Level
    Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).First() as Level;
    //Get SystemPipe
    FilteredElementCollector syscollector = new FilteredElementCollector(doc)
                                             .OfClass(typeof(PipingSystemType));
    ElementId pipeSysType = syscollector.FirstElementId();

    //
    Pipe newpipe;
    XYZ start = null;
    XYZ end = null;

    //Geometry Elements
    List<GeometryElement> geometrylist = new List<GeometryElement>();

    foreach (Element element in elementlist)
    {
        GeometryElement geometryElement = element.get_Geometry(new Options());
        geometrylist.Add(geometryElement);
    }

    //
    using (Transaction tx = new Transaction(doc, "create pipe"))
    {
        try
        {
            tx.Start();
            //
            List<Line> lines = new List<Line>();
            List<Pipe> pipeList = new List<Pipe>();
            

            foreach (GeometryElement geoElem in geometrylist)
            {
                foreach (GeometryObject geoObj in geoElem)
                {
                    Line line = geoObj as Line;
                    lines.Add(line);

                    start = line.GetEndPoint(0);
                    end = line.GetEndPoint(1);

                    if (pipeType != null)
                    {
                        newpipe = Pipe.Create(doc, pipeSysType, pipeType.Id, level.Id, start, end);
                        pipeList.Add(newpipe);

                        Element element = doc.GetElement(newpipe.Id);
                        
                        Parameter parameter = element.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
                        parameter.Set(10 * 0.00733);

                        //fitting Tee
                        ElementType teeType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeFitting)
                                                                                  .OfClass(typeof(ElementType))
                                                                                  .Cast<ElementType>()
                                                                                  .Where(x => x.FamilyName.Contains("Tee")).FirstOrDefault();
                          // Get FamilySymbol for Tap I want to use.

                        //FamilySymbol teeType = null;
                        //doc.LoadFamilySymbol(@"D:\M_Tee - PVC - Sch 40.rfa",
                        //    "MyTee", out teeType);

                        //// Symbol needs to be activated before use.

                        //if (!teeType.IsActive && teeType != null)
                        //{
                        //    teeType.Activate();
                        //    doc.Regenerate();
                        //}                                                         


                        RoutingPreferenceManager preferenceManager = newpipe.PipeType.RoutingPreferenceManager;
                        preferenceManager.AddRule(RoutingPreferenceRuleGroupType.Junctions, new RoutingPreferenceRule(teeType.Id, "MyTee"));
                        int routingPreferenceGroupCnt = preferenceManager.GetNumberOfRules(RoutingPreferenceRuleGroupType.Junctions);
                        if (routingPreferenceGroupCnt > 1)
                        {
                            for (int i = 0; i != routingPreferenceGroupCnt; i++)
                            {
                                preferenceManager.RemoveRule(RoutingPreferenceRuleGroupType.Junctions, 0);
                            }
                        }
                    }
                }
            }
            doc.Regenerate();

            for (int i = 0; i < pipeList.Count - 1; i++)
            {
                ConnectorManager pipe_conectorManager1 = pipeList[i].ConnectorManager;
                ConnectorSet pipe_connectorSet1 = pipe_conectorManager1.Connectors;
                //
                ConnectorManager pipe_conectorManager2 = pipeList[i + 1].ConnectorManager;
                ConnectorSet pipe_connectorSet2 = pipe_conectorManager2.Connectors;

                ConnectorManager pipe_conectorManager3 = pipeList[i + 2].ConnectorManager;
                ConnectorSet pipe_connectorSet3 = pipe_conectorManager3.Connectors;

                Connector pipe_connector1 = null;
                Connector pipe_connector2 = null;
                Connector pipe_connector3 = null;

                foreach (Connector connector1 in pipe_connectorSet1)
                {
                    if (connector1.Id == 0)
                    {
                        continue;
                    }

                    foreach (Connector connector2 in pipe_connectorSet2)
                    {
                        double minDist = double.MaxValue;
                        var punto2 = connector2.Origin;//{(55.838062275, -11.848221885, 0.000000000)}

                        double d = connector1.Origin.DistanceTo(connector2.Origin);
                        if (d < minDist)
                        {
                            pipe_connector1 = connector1;//{(55.838062275, -11.848221885, 0.000000000)}
                            pipe_connector2 = connector2;//{(55.838062275, -11.848221885, 0.000000000)}
                            minDist = d;
                        }
                    }
                }
                //
                foreach (Connector connector1 in pipe_connectorSet1)
                {
                    if (connector1.Id == 0)
                    {
                        continue;
                    }
                    foreach (Connector connector3 in pipe_connectorSet3)
                    {
                        if (connector3.Id == 1)
                        {
                            continue;
                        }
                        double minDist = double.MaxValue;
                        
                        double d = connector1.Origin.DistanceTo(connector3.Origin);
                       
                        if (d < minDist)
                        {
                            pipe_connector1 = connector1;
                            pipe_connector3 = connector3;
                            minDist = d;
                        }
                    }
                }

                //foreach (Connector connector2 in pipe_connectorSet2)
                //{
                //    if (connector2.Id == 0)
                //    {
                //        continue;
                //    }
                //    foreach (Connector connector3 in pipe_connectorSet3)
                //    {
                //        if (connector3.Id == 1)
                //        {
                //            continue;
                //        }
                //        double minDist = double.MaxValue;

                //        double d = connector2.Origin.DistanceTo(connector3.Origin);

                //        if (d < minDist)
                //        {
                //            pipe_connector2 = connector2;
                //            pipe_connector3 = connector3;
                //            minDist = d;
                //        }
                //    }
                //}

                var p1 = pipe_connector1.Origin;//{(55.838062275, -41.375780940, 0.000000000)}
                var p2 = pipe_connector2.Origin;//{(55.838062275, -41.375780940, 0.000000000)}
                var p3 = pipe_connector3.Origin;//{(55.838062275, -41.375780940, 0.000000000)}
                
                //doc.Create.NewTeeFitting(pipe_connector1, pipe_connector2, pipe_connector3);
                //doc.Create.NewTeeFitting(pipe_connector1, pipe_connector3, pipe_connector2);
                //doc.Create.NewTeeFitting(pipe_connector2, pipe_connector1, pipe_connector3);
                //doc.Create.NewTeeFitting(pipe_connector2, pipe_connector3, pipe_connector1);
                //doc.Create.NewTeeFitting(pipe_connector3, pipe_connector2, pipe_connector1);
                doc.Create.NewTeeFitting(pipe_connector3, pipe_connector1, pipe_connector2);
            }
            
            //
            foreach (Element elem in elementlist)
            {
                doc.Delete(elem.Id);
            }

            tx.Commit();
        }
        catch (Exception ex)
        {

            TaskDialog.Show("Info", "Error " + ex.Message);
            tx.RollBack();
        }

    }
}
#endregion

public Result Execute(
  ExternalCommandData commandData,
  ref string message,
  ElementSet elements)
{
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Application app = uiapp.Application;
    Document doc = uidoc.Document;

    var elementList = GetPipeLine(uidoc);
    CreatePipe(uidoc, elementList);

    return Result.Succeeded;
}

 

 

Labels (3)
2 REPLIES 2
Message 2 of 3
scgq425
in reply to: reylorente1

@reylorente1 :

Maybe you can manually remove the three connectors and then use this method to connect and see if an error is reported. Depending on your information, the three points may always be the cause of the error.

Message 3 of 3

I will be onest didn't read all this code but abaut NewTeeFiting:
so Tee fiting in revit is not from 3 pipes but from two pies. you input two connectors of pipe and 3 connector is for different pipe. Revit then split pipe put tee and set angle to match 3 connector.
The reason is that tee have to be on strait line. so if you have 3 pipes it will not work.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report