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: 

Please help me make one connection work between a duct or a pipe

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1020 Views, 4 Replies

Please help me make one connection work between a duct or a pipe

I'm using the DesignAutomation Framework to try and build API walls, doors, ceilings, floors, pipes, ducts. I need them in different variations and I need to be able to randomize their lengths, orientations and connections. I have been stuck within this connection space for two weeks and am so frustrated. I cannot find out why this doesn't work. The only error message I get is "failed to insert *whatever connection I call*" and that's it. No indication of why or how to fix it. There is no UI in this code, it's all API and DB functionality. I really would appreciate if someone could help me understand what I am doing wrong. In the example that I've provided, I simply try to make two ducts and connect them. I've read and tried what feels like a million different implementations from the forum as well as from BuildingCoder... nothing is working. There is always some kind of road block. What I really need is for someone to give me a clear code example of what I need to make this work just one darn time. 

 

        private static Duct CreateDuct(Document newDoc, XYZ p1, XYZ p2, double diameter)
        {
            FilteredElementCollector collector = new FilteredElementCollector(newDoc);
            collector.OfClass(typeof(Level));
            var elem = from element in collector where element.Name == "Floor" select element;
            Level level = elem.Cast<Level>().ElementAt<Level>(0);

            FilteredElementCollector elCollector = new FilteredElementCollector(newDoc).OfClass(typeof(DuctType)).WhereElementIsElementType();
            DuctType DT = elCollector.First() as DuctType;

            MEPSystemType mepSystemType = new FilteredElementCollector(newDoc)
                                         .OfClass(typeof(MEPSystemType))
                                         .Cast<MEPSystemType>()
                                         .FirstOrDefault(sysType => sysType.SystemClassification == MEPSystemClassification.SupplyAir);
            using (Transaction dTrans = new Transaction(newDoc, "Make Duct"))
            {
                dTrans.Start();
                Duct duct = Duct.Create(newDoc, mepSystemType.Id, DT.Id, level.Id, p1, p2);
                duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(diameter);
                dTrans.Commit();
                return duct;
            }

        } 

public static void ConnectTwoDucts(Document doc)
        {
            //create duct one
            XYZ pt1 = new XYZ(0, 0, 0);
            XYZ pt2 = new XYZ(0, 10, 0);
            Duct duct1 = CreateDuct(doc, pt1, pt2, 5);

            //create duct two
            XYZ pt3 = new XYZ(0, 15, 0);
            XYZ pt4 = new XYZ(0, 25, 0);
            Duct duct2 = CreateDuct(doc, pt3, pt4, 2);

            Connector duct1end = null;
            Connector duct2start = null;

            using (Transaction dConTrans = new Transaction(doc, "Connect Ducts"))
            {
                dConTrans.Start();

                //Load Family
                Family family = null;
                string path = @"C:\ProgramData\Autodesk\RVT 2020\Libraries\US Imperial\Duct\Fittings\Rectangular\Transitions";
                foreach (string dirFile in Directory.GetDirectories(path))
                {
                    foreach (string filename in Directory.GetFiles(dirFile))
                    {
                        doc.LoadFamily(filename, out family);
                    }
                }

                foreach (Connector connect1 in duct1.ConnectorManager.Connectors)
                {
                    if (connect1.Origin.IsAlmostEqualTo(pt2))
                    {
                        duct1end = connect1;
                        break;
                    }
                }

                foreach (Connector connect2 in duct2.ConnectorManager.Connectors)
                {
                    if (connect2.Origin.IsAlmostEqualTo(pt3))
                    {
                        duct2start = connect2;
                        break;
                    }
                }

                doc.Create.NewTransitionFitting(duct1end, duct2start);
                dConTrans.Commit();
            }
           

        }

 

4 REPLIES 4
Message 2 of 5
jeremytammik
in reply to: Anonymous

Trying to understand Revit purely from the API point is a pretty hopeless task.

 

I strongly suggest that you learn the basic fundamentals of the workflows you are interested in manually from the end user point of view before trying to address them programmatically.

 

In the end user interface, you might see some useful error messages that make sense, and understand the point of them.

 

Sorry for the bad news.

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5
MarryTookMyCoffe
in reply to: Anonymous

oh boy,  there is so much thing that you did wrong. You need to go back to revit and learn how systems works.

doc.Create.NewTransitionFitting(duct1end, duct2start)

this will only work if system have Transition, just loading family to project will not work.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 4 of 5
Anonymous
in reply to: MarryTookMyCoffe

I did finally get one thing to work with a duct tap take off by using the routing preference manager, but it only appears to have the options of setting a junction preference for tee and tap. 

 

RoutingPreferenceManager routePrefManager = ductType.RoutingPreferenceManager;
routePrefManager.PreferredJunctionType = PreferredJunctionType.Tap;

Is what you are saying is that instead of just creating a pipe or a duct and trying to connect them, I need to make a system before hand? Because I can just make a pipe or duct in Revit and connect it. I'm not fully understanding what you are trying to tell me to do.  

Message 5 of 5
MarryTookMyCoffe
in reply to: Anonymous

use revit lookup and add in manager, first is to see structure of class in revit second to run dll with app. Create DuctType in revit as user and than see bit by bit where all elements are stored, you can't cheat this, it is a lots of work. Read what kind of methods there are in RoutingPreferenceManager.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
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  

Autodesk Design & Make Report