MEP example needed ... create pipe segment

MEP example needed ... create pipe segment

Anonymous
Not applicable
6,234 Views
10 Replies
Message 1 of 11

MEP example needed ... create pipe segment

Anonymous
Not applicable

REVIT 2017, Windows 10, C#. Metric.

 

 

I downloaded the API samples; excellent for standard items like walls, wirnows etc. MEP is not included in the sample API items.

 

 

Need to create ppe segment using known coordinates positions of pipe ends; also known is the system name, pipe type nad diameter.


System:  Domestic Cold Water


Pipe Type: PVC-DWV


Diameter: 65mm

 

 

Included:


using Autodesk.Revit.DB.Plumbing;

 


Found method to create pipe...


Autodesk.Revit.DB.Plumbing.Pipe.Create(doc,sys1,pipetype1,level1.Id,new XYZ(0,0,0), new XYZ(1250,1010,0));

 


for doc and level I can use...


Document doc = ActiveUIDocument.Document;
 Level level1 = (Level)ElementFiltering.FindElement(doc, typeof(Level), "Level 1", null);

 


but I have no idea how to provide the system ID and pipe type ID ... please help ...

 

 

Thank You,


Kevin.

 

 

 

 

 

 

 

 

0 Likes
Accepted solutions (2)
6,235 Views
10 Replies
Replies (10)
Message 2 of 11

Mustafa.Salaheldin
Collaborator
Collaborator
Accepted solution

Please try the following code and tell me the results:

 

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_PipingSystem).Where(ps => ps.Name == "Domestic Cold Water");

            PipingSystem pipesystem = collector.Cast<PipingSystem>().FirstOrDefault();

            Autodesk.Revit.DB.Plumbing.Pipe.Create(doc, pipetype1.Id, pipesystem.Id, level1.Id, new XYZ(0, 0, 0), new XYZ(1250, 1010, 0));

If it satisfies your need please mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 3 of 11

jeremytammik
Autodesk
Autodesk
Accepted solution

http://thebuildingcoder.typepad.com/blog/2014/01/final-rolling-offset-using-pipecreate.html

 

Revit SDK sample AutoRoute

 

 By the way, a huge thanks to Mustafa for his more accurate answer and his innumerable other answers recently!

 

You are incredible, Mustafa!

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 11

Mustafa.Salaheldin
Collaborator
Collaborator

Dear Jeremy

 

Thanks a lot, you are my God Father and I dream of meeting you someday.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 5 of 11

Anonymous
Not applicable

Thank you, both of you.

I managed to get it working with the combined input provided by both of you.

It was really interesting to find that I needed to convert metric units to decimal feet in the XYZ positions.

Sorry I did not reply earlier, had a long weekend break directly after posting the question.

Thx for your patience.

Kevin.

 

0 Likes
Message 6 of 11

Anonymous
Not applicable

Dear all 

 

im trying to build a code to create a pipe, i built it with no errors but when i run the macro no pipes appear, can you please help me ?

 

using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.DB.Macros;
using Autodesk.Revit.UI.Events;
using Createnewpipe;
using Autodesk.Revit.UI.Plumbing;


namespace Createnewpipe
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("3BBE800A-AEF3-4E9D-885E-F80734647F78")]
    public partial class ThisDocument
    {
        private void Module_Startup(object sender, EventArgs e)
        {

        }

        private void Module_Shutdown(object sender, EventArgs e)
        {

        }

        #region Revit Macros generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(Module_Startup);
            this.Shutdown += new System.EventHandler(Module_Shutdown);
        }
        #endregion
        public void Createnewpipe()
        {
        }
        
     public static Pipe Createnewpipe(Document document, ElementId systemTypeId,  ElementId levelId )
{
         
         
     Document document = ActiveUIDocument.Document;
            
         ViewPlan view = document.ActiveView as ViewPlan;    
            Level level = view.GenLevel;
         
      // find a pipe system type
            FilteredElementCollector sysCollector = new FilteredElementCollector(document);
            sysCollector.OfClass(typeof(PipingSystemType));
            ElementId pipeSysTypeId = sysCollector.FirstElementId();
            
    // find a pipe type
            
    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.OfClass(typeof(PipeType));
    PipeType pipeType = collector.FirstElement() as PipeType;
            
    Pipe pipe = null;
    if (null != pipeType)
    {
        // create pipe between 2 points
        XYZ p1 = new XYZ(10000);
        XYZ p2 = new XYZ(100001000);

        pipe = Pipe.Create(document, systemTypeId, pipeType.Id, levelId, p1, p2);
        
    }

    return pipe;
}
    }
}

0 Likes
Message 7 of 11

jeremytammik
Autodesk
Autodesk

I do not see you starting or committing any transaction.

 

You cannot modify the database without that.

 

If you are new to the Revit API, please start by working through the getting started material:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Then, read about transaction handling:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.53

 

Once you have that under your belt, check out this series of posts on creating a rolling offset:

 

It demonstrates several ways of calculating, creating and connecting pipes and fittings:

 

http://thebuildingcoder.typepad.com/blog/2014/01/final-rolling-offset-using-pipecreate.html

 

Good luck and have fun exploring!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 11

Anonymous
Not applicable

thanks mr Jeremy,finally I created pipe by API    

0 Likes
Message 9 of 11

aris.aquino
Contributor
Contributor

Hi Jeremy,

 

Is there a way to create pipe segments using mouse clicks rather than the hard coded XYZ values?

 

 

Thanks,

AJ

0 Likes
Message 10 of 11

recepagah12
Advocate
Advocate

You can prompt the user to select a point and use it as XYZ input.

 

 XYZ point = uidoc.Selection.PickPoint("Pick a pipe segment location");

 

I hope this helps,

Recep.

0 Likes
Message 11 of 11

aris.aquino
Contributor
Contributor

Thanks Recep! Works great!

 

AJ

0 Likes