Skip to content

Instantly share code, notes, and snippets.

@ricaun
Last active May 10, 2023 14:43
Show Gist options
  • Save ricaun/4f62b8650d29f1ff837e7e77f9e8b552 to your computer and use it in GitHub Desktop.
Save ricaun/4f62b8650d29f1ff837e7e77f9e8b552 to your computer and use it in GitHub Desktop.
Revit Addin Commands to create Pipe and FlexPipe
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
using System;
using System.ComponentModel;
namespace RevitAddin.Youtube.Revit.Commands
{
[DisplayName("Create Conduit")]
[Designer("/UIFrameworkRes;component/ribbon/images/conduit_draw.ico")]
[Transaction(TransactionMode.Manual)]
public class CommandCreateConduit : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;
Document document = uiapp.ActiveUIDocument.Document;
var levels = new FilteredElementCollector(document)
.OfClass(typeof(Level));
var levelId = levels.FirstElementId();
var conduitTypes = new FilteredElementCollector(document)
.OfClass(typeof(ConduitType));
var conduitTypeId = conduitTypes.FirstElementId();
using (Transaction transaction = new Transaction(document))
{
transaction.Start("Create Conduit");
Conduit.Create(document, conduitTypeId, XYZ.Zero, 10 * XYZ.BasisZ, levelId);
transaction.Commit();
}
return Result.Succeeded;
}
}
}
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.ComponentModel;
namespace RevitAddin.Commands
{
[DisplayName("Create Pipe")]
[Designer("/UIFrameworkRes;component/ribbon/images/pipe_create.ico")]
[Transaction(TransactionMode.Manual)]
public class CommandCreatePipe : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;
Document document = uiapp.ActiveUIDocument.Document;
var levels = new FilteredElementCollector(document)
.OfClass(typeof(Level));
var levelId = levels.FirstElementId();
var pipeTypes = new FilteredElementCollector(document)
.OfClass(typeof(PipeType));
var pipeTypeId = pipeTypes.FirstElementId();
var pipeSystemTypes = new FilteredElementCollector(document)
.OfClass(typeof(PipingSystemType));
var pipeSystemTypeId = pipeSystemTypes.FirstElementId();
using (Transaction transaction = new Transaction(document))
{
transaction.Start("Create Pipe");
Pipe.Create(document, pipeSystemTypeId, pipeTypeId, levelId, XYZ.Zero, 10 * XYZ.BasisX);
transaction.Commit();
}
return Result.Succeeded;
}
}
[DisplayName("Create FlexPipe")]
[Designer("/UIFrameworkRes;component/ribbon/images/flex_pipe_create.ico")]
[Transaction(TransactionMode.Manual)]
public class CommandCreateFlexPipe : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;
Document document = uiapp.ActiveUIDocument.Document;
var levels = new FilteredElementCollector(document)
.OfClass(typeof(Level));
var levelId = levels.FirstElementId();
var pipeTypes = new FilteredElementCollector(document)
.OfClass(typeof(FlexPipeType));
var pipeTypeId = pipeTypes.FirstElementId();
var pipeSystemTypes = new FilteredElementCollector(document)
.OfClass(typeof(PipingSystemType));
var pipeSystemTypeId = pipeSystemTypes.FirstElementId();
using (Transaction transaction = new Transaction(document))
{
transaction.Start("Create FlexPipe");
XYZ startTangent = XYZ.BasisY;
XYZ endTangent = XYZ.BasisY;
var points = new List<XYZ>() { XYZ.Zero, 5 * XYZ.BasisY + XYZ.BasisZ, 10 * XYZ.BasisY };
FlexPipe.Create(document, pipeSystemTypeId, pipeTypeId, levelId, startTangent, endTangent, points);
transaction.Commit();
}
return Result.Succeeded;
}
}
}
@ricaun
Copy link
Author

ricaun commented Feb 20, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment