Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Namespaces
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Windows.Forms.VisualStyles;
- using Autodesk.Revit.ApplicationServices;
- using Autodesk.Revit.Attributes;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Plumbing;
- using Autodesk.Revit.UI;
- using Autodesk.Revit.UI.Selection;
- #endregion
- namespace PipeCreate
- {
- [Transaction(TransactionMode.Manual)]
- public class Command : IExternalCommand
- {
- public Result Execute(
- ExternalCommandData commandData,
- ref string message,
- ElementSet elements)
- {
- UIApplication uiapp = commandData.Application;
- UIDocument uidoc = uiapp.ActiveUIDocument;
- Application app = uiapp.Application;
- Document doc = uidoc.Document;
- // Extract all pipe system types
- var mepSystemTypes
- = new FilteredElementCollector(doc)
- //.WhereElementIsNotElementType()
- .OfClass(typeof(PipingSystemType))
- .OfType<PipingSystemType>()
- .ToList();
- // get the Domestic hot water type
- var domesticHotWaterSystemType =
- mepSystemTypes
- .FirstOrDefault(st => st.SystemClassification == MEPSystemClassification.DomesticHotWater);
- if (domesticHotWaterSystemType == null)
- {
- message = "Could not found Domestic Hot Water System Type";
- return Result.Failed;
- }
- // looking for the PipeType
- var pipeTypes =
- new FilteredElementCollector(doc)
- .OfClass(typeof (PipeType))
- .OfType<PipeType>()
- .ToList();
- // get the first type from the collection
- var firstPipeType =
- pipeTypes.FirstOrDefault();
- if (firstPipeType == null)
- {
- message = "Could not found Pipe Type";
- return Result.Failed;
- }
- var level = uidoc.ActiveView.GenLevel;
- if (level == null)
- {
- message = "Wrong Active View";
- return Result.Failed;
- }
- var startPoint = XYZ.Zero;
- var endPoint = new XYZ(100, 0, 0);
- using (var t = new Transaction(doc, "Create pipe using Pipe.Create"))
- {
- t.Start();
- var pipe = Pipe.Create(doc,
- domesticHotWaterSystemType.Id,
- firstPipeType.Id,
- level.Id,
- startPoint,
- endPoint);
- t.Commit();
- }
- return Result.Succeeded;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement