Advertisement
chekalin-v

Create new Pipe using Pipe.Create

Jan 22nd, 2014
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. #region Namespaces
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Windows.Forms.VisualStyles;
  7. using Autodesk.Revit.ApplicationServices;
  8. using Autodesk.Revit.Attributes;
  9. using Autodesk.Revit.DB;
  10. using Autodesk.Revit.DB.Plumbing;
  11. using Autodesk.Revit.UI;
  12. using Autodesk.Revit.UI.Selection;
  13. #endregion
  14.  
  15. namespace PipeCreate
  16. {
  17.     [Transaction(TransactionMode.Manual)]
  18.     public class Command : IExternalCommand
  19.     {
  20.         public Result Execute(
  21.           ExternalCommandData commandData,
  22.           ref string message,
  23.           ElementSet elements)
  24.         {
  25.             UIApplication uiapp = commandData.Application;
  26.             UIDocument uidoc = uiapp.ActiveUIDocument;
  27.             Application app = uiapp.Application;
  28.             Document doc = uidoc.Document;
  29.  
  30.             // Extract all pipe system types
  31.             var mepSystemTypes
  32.               = new FilteredElementCollector(doc)
  33.                 //.WhereElementIsNotElementType()                
  34.                 .OfClass(typeof(PipingSystemType))
  35.                 .OfType<PipingSystemType>()
  36.                 .ToList();
  37.  
  38.             // get the Domestic hot water type
  39.             var domesticHotWaterSystemType =
  40.                 mepSystemTypes
  41.                     .FirstOrDefault(st => st.SystemClassification == MEPSystemClassification.DomesticHotWater);
  42.  
  43.             if (domesticHotWaterSystemType == null)
  44.             {
  45.                 message = "Could not found Domestic Hot Water System Type";
  46.                 return Result.Failed;
  47.             }
  48.  
  49.             // looking for the PipeType
  50.             var pipeTypes =
  51.                 new FilteredElementCollector(doc)
  52.                     .OfClass(typeof (PipeType))
  53.                     .OfType<PipeType>()
  54.                     .ToList();
  55.  
  56.             // get the first type from the collection
  57.             var firstPipeType =
  58.                 pipeTypes.FirstOrDefault();
  59.  
  60.             if (firstPipeType == null)
  61.             {
  62.                 message = "Could not found Pipe Type";
  63.                 return Result.Failed;
  64.             }
  65.  
  66.            
  67.             var level = uidoc.ActiveView.GenLevel;
  68.  
  69.             if (level == null)
  70.             {
  71.                 message = "Wrong Active View";
  72.                 return Result.Failed;
  73.             }
  74.  
  75.  
  76.             var startPoint = XYZ.Zero;
  77.  
  78.             var endPoint = new XYZ(100, 0, 0);
  79.  
  80.             using (var t = new Transaction(doc, "Create pipe using Pipe.Create"))
  81.             {
  82.                 t.Start();
  83.                 var pipe = Pipe.Create(doc,
  84.                     domesticHotWaterSystemType.Id,
  85.                     firstPipeType.Id,
  86.                     level.Id,
  87.                     startPoint,
  88.                     endPoint);
  89.  
  90.                 t.Commit();
  91.             }
  92.  
  93.             return Result.Succeeded;
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement