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: 

Insert valve into pipe

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
p.serek
1625 Views, 5 Replies

Insert valve into pipe

Hi, 

 

I want to create pipe line programmatically. I can already place pipes and elbows or tees but what about valves? I can insert them as a normal family instances but how to make them a part of pipe? How to resize them to fit pipe's diameter? In Revit I can just drag'n'drop it on pipe and valve adapts as needed.

 

I've tried this:

var inst = doc.Create.NewFamilyInstance(valve, symbol, pipe, StructuralType.NonStructural);

So it's this overload:

public FamilyInstance NewFamilyInstance(XYZ location, DB.FamilySymbol symbol, DB.Element host, StructuralType structuralType);

Is it a metter of a specific overload that would do the job? Or maybe I have to operate on an instance to make it fit?

 

I place the line this way:

  1. I've got coordinates of pipes' ends, elbows' positions, valves' positions
  2. I place pipes, then connect elbows
  3. Now I have to somehow fit valves into breaks in pipes

 

I've also tried to merge two pipes to delete breaks and insert valves into whole pipe (as it is in Revit) but that also doesn't work for me.

 

Please help he.

 

Regards,

Przemek

Tags (3)
Labels (3)
5 REPLIES 5
Message 2 of 6
danielpinheiro860
in reply to: p.serek

Hi,

 

To insert a union, tee or other pipe fitting, you first need to use BreakCurve method, and split pipe at the point where you want to insert the fitting. After that, you need to iterate over the Connectors inside the ConnectorSet from pipe and find the two connectors with whe minimal distance between each other, and create your fitting using this two connectors. I am sharing a code below that realize this chore for union fitting, hope can helps you. 

 

 

foreach (Reference reference in references)
                {
                    Pipe pipe = doc.GetElement(reference.ElementId) as Pipe;
                    LocationCurve locationCurve = pipe.Location as LocationCurve;
                    Curve pipeCurve = locationCurve.Curve;
                    XYZ midPoint = pipeCurve.Evaluate(0.2, true);

                    using (var trans = new Transaction(doc))
                    {
                        trans.Start("Internal Transaction");

                        ElementId newPipeId = PlumbingUtils.BreakCurve(doc, pipe.Id, midPoint);
                        Pipe newPipe = doc.GetElement(newPipeId) as Pipe;
                        foreach (Connector connector in pipe.ConnectorManager.Connectors)
                        {
                            XYZ connectorOriginPoint = connector.Origin;
                            ConnectorSet newPipeConnectorSet = newPipe.ConnectorManager.Connectors;

                            foreach (Connector newConnector in newPipeConnectorSet)
                            {
                                if (newConnector.Origin.DistanceTo(connectorOriginPoint) < 0.01)
                                {
                                    try
                                    {
                                        doc.Create.NewUnionFitting(connector, newConnector);
                                    }
                                    catch { }
                                    break;
                                }
                            }
                        }

                        trans.Commit();
                    }
                }

 

 

Message 3 of 6
p.serek
in reply to: danielpinheiro860

Thank you for your reply!

 

But I can't still insert a valve itsefl. There is no method like NewValve(Connector conn1, Connector conn2) to place it by connectors. When I place a valve (NewFamilyInstance method)  and then connect it to pipes it works a little bit, because they're connecte but valve's size and diameter isn't appropriete. Any suggestions?

 

pserek_0-1646737576195.png

 

Regards,

Przemek

Message 4 of 6
jeremy_tammik
in reply to: p.serek

I have not worked with valves, but I found my research on creating a rolling offset extremely illuminating, so maybe you will find it useful as well:

 

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

 

My main take-away was: 

 

  • I can place pipes first and then insert fittings, letting Revit place and adapt them automatically
  • I can place only fittings (and maybe valves also?) first, with no pipes at all, and then simply connect them to let Revit create and place and adapt all the pipes automatically

  

 

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 6
danielpinheiro860
in reply to: p.serek

You're correct. There is no method for insert a valve, at least directly, those fittings methods works fine for some Routing Preferences fittings, that was my case. For this other approach, I dont know if is the best solution, but I've tried before and this workaround worked for me: 

 

1. Split your pipe where you want to insert the valve;

2. Use the method NewFamilyInstance to create and insert your valve at this point;

3. Iterate over the pipe connectors where "Connector.IsConnected == false" and use the method  "yourPipeConnector.ConnectTo(yourValveConnector)" to connect your valve into the suitable pipe connectors, you can use the method "yourPipeConnector.Origin.DistanceTo(yourValveConnector.Origin)", to help on this chore as well;

4. Set the correct diameter parameter of your valve, accordingly with the pipe diameter;

 

Message 6 of 6
p.serek
in reply to: danielpinheiro860

Thank you very much!

I'm doing almost the same thing BUT I forgot I can manually change diameter... That will help me a lot. Thanks once again!

Regards,
Przemek

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

Post to forums  

Rail Community


Autodesk Design & Make Report