Creating a pipe or flex pipe by loading a family

Creating a pipe or flex pipe by loading a family

Anonymous
Not applicable
424 Views
4 Replies
Message 1 of 5

Creating a pipe or flex pipe by loading a family

Anonymous
Not applicable

I'm completely new to the Revit API and am having trouble simply loading a family and using it to create a pipe or flex pipe. I'm sure there is something simple I am missing, and I've had success with things like doors and tables, however I'm completely baffled with creating even a simple pipe that goes from A to B beyond just the default pipe option (I've included the code I used to make a default flex pipe and default pipe - my only success). I have not been successful in finding example code online (I have scoured The Building Coder and have not found enough pieces to put this together). If someone can give me a basis to work from I would be so grateful.

 

Working FlexPipe:

        private static void CreateFlexPipe(Document newDoc, Wall wall)
        {

            FilteredElementCollector collector = new FilteredElementCollector(newDoc);
            collector.OfClass(typeof(FlexPipeType));
            ElementId pipeTypeId = collector.FirstElementId();

            FilteredElementCollector sysCollector = new FilteredElementCollector(newDoc);
            sysCollector.OfClass(typeof(PipingSystemType));
            ElementId pipeSysTypeId = sysCollector.FirstElementId();

            Level levelId = newDoc.GetElement(wall.LevelId) as Level;

            FlexPipe pipe = null;
            if (pipeTypeId != ElementId.InvalidElementId && pipeSysTypeId != ElementId.InvalidElementId)
            {
                List<XYZ> points = new List<XYZ>();
                points.Add(new XYZ(0, 0, 0));
                points.Add(new XYZ(10, 10, 0));
                points.Add(new XYZ(10, 0, 0));

                pipe = FlexPipe.Create(newDoc, pipeSysTypeId, pipeTypeId, levelId.Id, points);
            }
        }

Working Pipe:

        private static void CreatePipe(Document newDoc, Wall wall)
        {

            FilteredElementCollector collector = new FilteredElementCollector(newDoc);
            collector.OfClass(typeof(PipeType));
            ElementId pipeTypeId = collector.FirstElementId();

            FilteredElementCollector sysCollector = new FilteredElementCollector(newDoc);
            sysCollector.OfClass(typeof(PipingSystemType));
            ElementId pipeSysTypeId = sysCollector.FirstElementId();

            Level levelId = newDoc.GetElement(wall.LevelId) as Level;

            Pipe pipe1 = null;

            if (pipeTypeId != ElementId.InvalidElementId && pipeSysTypeId != ElementId.InvalidElementId)
            {
                XYZ p1 = new XYZ(0, 0, 0);
                XYZ p2 = new XYZ(10, 10, 0);

                pipe1 = Pipe.Create(newDoc, pipeSysTypeId, pipeTypeId, levelId.Id, p1, p2);

            }

        }

Also here is where I am at with trying to load a family:

private static void TestLoadFamily(Document newDoc)
        {
            string filename = @"C:\ProgramData\Autodesk\RVT 2020\Libraries\US Metric\Pipe\Actual Pipe\JONATHAN39S_METRIC_PIPE_HORIZONTAL_30MM_PIPE_THICK_2825.rfa";

            FilteredElementCollector levelCollector = new FilteredElementCollector(newDoc);
            levelCollector.OfClass(typeof(Level));
            ElementId someLevelId = levelCollector.FirstElementId();

            FilteredElementCollector sysCollector = new FilteredElementCollector(newDoc);
            sysCollector.OfClass(typeof(PipingSystemType));
            ElementId pipeSysTypeId = sysCollector.FirstElementId();

            using (Transaction familyTrans = new Transaction(newDoc, "Use a Family"))
            {
                familyTrans.Start();

                Family family = null;
                if (!newDoc.LoadFamily(filename, out family))
                {
                    throw new Exception("Unable to load " + filename);
                }

                ISet<ElementId> familySymbolIds = family.GetFamilySymbolIds();

                int count = 0;
                foreach (ElementId id in familySymbolIds)
                {
                    if (count == 0)
                    {
                        FamilySymbol pipeSymbol = family.Document.GetElement(id) as FamilySymbol;
                        if (!pipeSymbol.IsActive)
                        {
                            pipeSymbol.Activate();
                            newDoc.Regenerate();
                        }
                        Pipe pipe = null;
                        XYZ p1 = new XYZ(0, 0, 0);
                        XYZ p2 = new XYZ(10, 10, 0);

                        pipe = Pipe.Create(newDoc, pipeSysTypeId, pipeSymbol.Id, someLevelId, p1, p2);
                    }
                    count++;
                }
                familyTrans.Commit();
            }
        }

This errors with: "The pipe type pipeTypeId is not valid pipe type."

 

*Note: I am using the DesignAutomationHandler and build within another project. 

0 Likes
425 Views
4 Replies
Replies (4)
Message 2 of 5

s.borello
Advisor
Advisor

Don't know what you're trying to do...seems like you're overthinking a bit.  Plus, there is an API forum where you may get more attention.  I would just toggle on the system tab: piping tools, and model the pipe that way.  Good luck!

 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you, I will re-post in that forum.

0 Likes
Message 4 of 5

s.borello
Advisor
Advisor

If you want you can simply report your post to admin and they will move it for you, rather than recreate the post.

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks again, I've already copied and pasted the post 🙂

0 Likes