Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Available Pipe Sizes per Type of Pipe

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
zrodgersTSSSU
1875 Views, 4 Replies

Get Available Pipe Sizes per Type of Pipe

Hey Everyone, I have a plugin where I launch a form that lets you pick the System Type & Pipe Type. Right now im using a user input double to set the pipe diameter. But I wanted to create a dropdown in the form that has the sizes for the pipe type.

 

example

zrodgersTSSSU_0-1623932271855.png

 

I know you are supposed to iterate through the segments to get the sizes as shown in the link below but I only have one pipe segment type for each pipe type(name). So i want to be able to select the pipe type(name) "ductile iron" and then populate a list of the available sizes into the comboBox. is it possible to do this without getting the segments?

 

link to getting sizes from segment:

https://thebuildingcoder.typepad.com/blog/2015/02/list-pipe-sizes-and-more-obsolete-api-usage-remova...

 

I dont want the user to have to select a pipe segment type because there is only one per Pipe Type(name)

 

Here is my Form:

zrodgersTSSSU_0-1623932918811.png

 

 

Form Code:

 

public PipeCreationForm(Autodesk.Revit.UI.ExternalCommandData commandData)
        {
            InitializeComponent();

            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            //levels
            FilteredElementCollector levels = new FilteredElementCollector(uidoc.Document);
            List<Level> levelCol = levels.OfClass(typeof(Level)).OfType<Level>().OrderBy(lev => lev.Elevation).ToList();
            sLevel.DataSource = new List<Level>(levelCol);
            sLevel.DisplayMember = "Name";
            if (levelCol.Any())
            {
                sLevel.SelectedIndex = 0;
            }

            //System Type
            FilteredElementCollector mepSystem = new FilteredElementCollector(uidoc.Document);
            List<PipingSystemType> systemTypeCol = mepSystem.OfClass(typeof(PipingSystemType)).OfType<PipingSystemType>().OrderBy(x => x.Name).ToList();
            pSysType.DataSource = new List<PipingSystemType>(systemTypeCol);
            pSysType.DisplayMember = "Name";
            if (systemTypeCol.Any())
            {
                pSysType.SelectedIndex = 0;
            }

            //pipe types
            FilteredElementCollector pipeType = new FilteredElementCollector(uidoc.Document);
            List<PipeType> pipeTypeCol = pipeType.OfClass(typeof(PipeType)).OfType<PipeType>().ToList();
            pType.DataSource = new List<PipeType>(pipeTypeCol);
            pType.DisplayMember = "Name";
            if (pipeTypeCol.Any())
            {
                pType.SelectedIndex = 0;
            }
            
            //find segment sizes based on selected pipe type
            
        }

 

 

Sorry if this has been asked before i didnt see it anywhere.

4 REPLIES 4
Message 2 of 5

Hey,

 

I couldn`t figure out directly what you need but I found an alternative that might work.

 

Sizes are related with Pipe Segments. Every Pipe has a Instance parameter where you can Read the assigned Pipe Segment. In addition, the Pipe Segments available for each instance are added from the Type. So, Pipe Segments are also related with the Type.

 

That being said, what I did was the following:

 

1. Collect all pipe segments by Category.

2. Create a dictionary containing the names and sizes as key value.

3. Select an instance, get the pipe segment name assigned to this instance.

4. Search the dictionary for available sizes.

5. Set the size.

 

As you could have a model without pipe instances created, I would do the following modification on the UI:

 

1. Move the pipe diameter to a Second Window where the user can select the Size.

2. From Win1 to Win2, Create the pipe instance with all values excepting the size.

3. Get the available sizes the created instance.

4. Show a new window with the available size the user can select.

 

The only difference is you have two steps instead of one. But if you are able to get the Available Pipe Segments from the PipeType, this problem is solved. if not, I think this alternative might work. 

 

This is the code I run, the only thing you should do is is change the selection by UI to selection of created instances:

 

 

UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Application app = uiApp.Application;
Document doc = uiDoc.Document;

FilteredElementCollector pipeSegments = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeSegments);

Dictionary<string,List<string>> pipeSegmentSizes = new Dictionary<string, List<string>>();

Reference pickObject = uiDoc.Selection.PickObject(ObjectType.Element);
Pipe pipe = doc.GetElement(pickObject.ElementId) as Pipe;
string segmentPipeName = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_SEGMENT_PARAM).AsValueString();
              
foreach (Segment segment in pipeSegments)
{
    string key = segment.Name;
    List<string> diameters = new List<string>();
    if (!pipeSegmentSizes.ContainsKey(key)) 
    {
        foreach(MEPSize ms in segment.GetSizes())
        if(ms != null && key == segmentPipeName) diameters.Add(ms.NominalDiameter.ToString());
    } 
    pipeSegmentSizes.Add(key, diameters);
                    
}
return Autodesk.Revit.UI.Result.Succeeded;

 

 

 

I hope it helps,

Kind regards.

Github:
https://github.com/franpossetto
Message 3 of 5

I don't see why can't you just use

RoutingPreferenceManager

with 

RoutingPreferenceRuleGroupType.Segments

from it you can get mep size, min and max.

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 4 of 5

Sorry for the late response I was on Vacation Last Week! That worked for me! Thank you both for the responses.

Message 5 of 5

Glad to read that!

Github:
https://github.com/franpossetto

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community