Adding couplings to pipe.

Adding couplings to pipe.

Anonymous
Not applicable
2,863 Views
13 Replies
Message 1 of 14

Adding couplings to 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 (2)
2,864 Views
13 Replies
Replies (13)
Message 2 of 14

Aaron.Lu
Autodesk
Autodesk
Dear Anusha, what is the problem of your code for slanted or vertical pipes? would you please upload some screenshot?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 14

Anonymous
Not applicable

Hi,

 

Thanks for your reply..

 

The code is not working for both Vertical and slant pipes.

I am attaching the screen shot.

0 Likes
Message 4 of 14

Anonymous
Not applicable

Hi,

 

Now i am facing different issue. Like pipe may be in any direction its spliting, But the pipe location is moving to some other location.

I am doing like this,

 

Can any one help me to solve this issue.

 

Below is the code:

Curve c1 = (pipes[0].Location as LocationCurve).Curve;

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

 

q0 = p00;

q1 = q0 + m_divide_val * p00.Normalize();

m_pipes = CreateNewPipe(m_document, q0, q1);

p00 += ((m_divide_val + .5) * p00.Normalize());

 

Here i am substracting the end location with the start location, because of this only the pipe location is moving after creating new pipe.

I have attached the output of my code for refrence..

Please provide me solution.

 

Thank you very much in advance.

 

0 Likes
Message 5 of 14

Aaron.Lu
Autodesk
Autodesk
1. Does the old problem still exist?
2. What is the problem of new problem? or, whichi image is the expected result? after*.JPG or A_*.JPG?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 6 of 14

Anonymous
Not applicable

Thank you very much for the reply..

 

Still the old problem existing.

 

1)If i use the below code

 

XYZ p00 = c1.GetEndPoint(0);

for(i = 0; i < final_count; i++)

{

 //creating pipes based on the location of current pipe.

q0 = p00;

q1 = q0 + m_divide_val * XYZ.BasisX;

m_pipes = CreateNewPipe(m_document, q0, q1);

p00 += ((m_divide_val + .5) *XYZ.BasisX);

}

 

in floor plan view, its working for only Horizantal pipes. If i have to work with vertical and Slope pipes how to modify the above code?

 

 

2)And if use the below code:

 

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

p00.Normalize();

for(i = 0; i < final_count; i++)

{

  q0 = p00;

  q1 = q0 + m_divide_val * p00.Normalize();

  m_pipes = CreateNewPipe(m_document, q0, q1);

  p00 += ((m_divide_val + .5) * p00.Normalize());

}

 

Newly created pipes are shifting to the other location as shown in the after_runningcode_H.JPG and A_runningcode_S.jpg.

after_runningcode_H.JPG and A_runningcode_S.jpg are the output of the code.

Beforerunningcode_Horizantal is the original location of the pipe.

 

In the code m_divide_val is the lenght of the original pipe is divided the length by 1000, and i am creating the each pipe of the 1000 mm.

0 Likes
Message 7 of 14

Anonymous
Not applicable

Please find the attached screens for the code:

 

XYZ p00 = c1.GetEndPoint(0);

for(i = 0; i < final_count; i++)

{

//creating pipes based on the location of current pipe.

q0 = p00;

q1 = q0 + m_divide_val * XYZ.BasisX;

m_pipes = CreateNewPipe(m_document, q0, q1);

p00 += ((m_divide_val + .5) *XYZ.BasisX);

}

 

A_running_H is the output after running the code.

B_running_H is the output before running the code.

0 Likes
Message 8 of 14

Aaron.Lu
Autodesk
Autodesk
Ok, I finally got u.

It is a problem of your algorithm. and I think what you need is this:

var startPoint = c1.GetEndPoint(0);
var midPoint = c1.Evaluate(len / 2, false); //whatever length here
var endPoint = c1.GetEndPoint(1);


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 9 of 14

Anonymous
Not applicable

Thank you very much for the solution....

 

I'll try this.. Amd i'll let you know the result..

 

Thnaks a lot...

0 Likes
Message 10 of 14

Anonymous
Not applicable

Hi Aaron.Lu,

 

var startPoint = c1.GetEndPoint(0);
var midPoint = c1.Evaluate(len / 2, false); //whatever length here
var endPoint = c1.GetEndPoint(1);

 

Can you plaese brief these code, i am not understanding properly,

I am new to this Revit API..

 

Thank you in advance..

0 Likes
Message 11 of 14

Aaron.Lu
Autodesk
Autodesk
Accepted solution
c1.Evaluate(length, false) is to get a point with the distance "length" to the start point of the curve, so you want to get 1000mm distance point to the start point, you can use c1.Evaluate(1000 * 0.0032808, false).
for 2000, use c1.Evaluate(2000 * 0.0032808, false).

is it helpful?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 12 of 14

Anonymous
Not applicable
Accepted solution

Hi As you suggested i tried.. And i got proper output also..

Thank you very much.. I am very happy..

Thanks a lot....

 

 

0 Likes
Message 13 of 14

Anonymous
Not applicable

Thank you Aaron.Lu ..

0 Likes
Message 14 of 14

Aaron.Lu
Autodesk
Autodesk
You are welcome, Glad to see it works!


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes