Adding couplings on pipe.

Adding couplings on pipe.

Anonymous
Not applicable
1,188 Views
1 Reply
Message 1 of 2

Adding couplings on pipe.

Anonymous
Not applicable

Hi,

 

The below code is splitting the pipe and adding the coupling perfectly, if the line is straight.

Offset is going to negative side, and the pipe diameter is always showing as 200m in the Revit, if i check in the application the pipe diameter is same as the original pipe.

 

Please can anyone suggest me, how to work if the pipe is having any angles or the pipe is vertical.

Thank you very much in advance.

 

// code

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(PipeType));
PipeType pipeType = collector.FirstElement() as PipeType;

Selection sel = uidoc.Selection;
foreach (Element e in sel.Elements)
{
Pipe c = e as Pipe;
if (null != c)
{
pipes.Add(c);
if (2 == pipes.Count)
{
break;
}
}
}

tx.Start("split pipe");

Curve c1 = (pipes[0].Location as LocationCurve).Curve;// selecting one pipe and taking its location.

 

XYZ p00 = c1.GetEndPoint(0);
XYZ p01 = c1.GetEndPoint(1);

 

// finding thte length of the selected pipe.

double len = pipes[0].get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
len = len / 2; //dividing the length.

// creatin first pipe

XYZ q0 = p00;
XYZ q1 = p01 - len * XYZ.BasisX;

Pipe pipe = null;
if (null != pipeType)
{
pipe = doc.Create.NewPipe(q0, q1, pipeType);
}

 

// creatin first pipe

XYZ q2 = p01;
XYZ q3 = p01 - (len - 1) * XYZ.BasisX;

Pipe pipe1 = null;
if (null != pipeType)
{
pipe1 = doc.Create.NewPipe(q2, q3, pipeType);
}

Connector pipe2_start = null;
Connector pipe2_end = null;

double dist = double.MaxValue;
foreach (Connector c in pipe.ConnectorManager.Connectors)
{
XYZ p = c.Origin;
double d = p.DistanceTo(q1);

if (d < dist)
{
dist = d;
pipe2_start = c;
}
break;
}
foreach (Connector conn in pipe1.ConnectorManager.Connectors)
{
if (conn.Origin.IsAlmostEqualTo(q3))
{
pipe2_end = conn;
}
}
FamilyInstance takeoff = doc.Create.NewUnionFitting(pipe2_start, pipe2_end);
DeleteElement(doc, pipes[0]);
tx.Commit();

0 Likes
Accepted solutions (1)
1,189 Views
1 Reply
Reply (1)
Message 2 of 2

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Dear Anusha, is it duplicated with this? http://forums.autodesk.com/t5/revit-api/adding-couplings-to-pipe/m-p/5564601#U5564601


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes