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:
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
Solved! Go to Solution.
Solved by danielpinheiro860. Go to Solution.
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();
}
}
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?
Regards,
Przemek
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:
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;
Can't find what you're looking for? Ask the community or share your knowledge.