Creating a pipe or flex pipe by loading a family

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.