By Joe Ye
As there is no sample code in Revit SDK or the community showing how to create conduit. I wrote this one for an example.
Note, the method to create conduit is under Conduit class. Revit now try to put the element creation method under the class instead of Autodesk.Revit.Creation.Document.
Here is the C# code to create a 10 feet conduit.
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Autodesk.Revit .DB.Electrical.ConduitType));
Autodesk.Revit .DB.Electrical.ConduitType type = collector.FirstElement() as Autodesk.Revit .DB.Electrical.ConduitType;
FilteredElementCollector collector2 = new FilteredElementCollector(doc);
collector2.OfClass(typeof(Level));
Level level = collector2.FirstElement() as Level;
Transaction trans = new Transaction(doc);
trans.Start("createConduit");
Autodesk.Revit.DB.Electrical.Conduit.Create(doc, type.Id,new XYZ(0,0,0),new XYZ(10,0,0),level.Id);
trans.Commit();
return Result.Succeeded ;
}
}