Split a pipe at a specific lenght

Split a pipe at a specific lenght

Anonymous
Not applicable
3,907 Views
16 Replies
Message 1 of 17

Split a pipe at a specific lenght

Anonymous
Not applicable

Please suggest how to split the pipe using revit API 2014,

I gone through many links and found there is no direct method to split the pipe.

 

0 Likes
3,908 Views
16 Replies
Replies (16)
Message 2 of 17

jeremytammik
Autodesk
Autodesk

Can you achieve what you want through the user interface?

 

If so, how?

 

If not, the Revit API will probably not help either.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 17

Anonymous
Not applicable

Yes it is possible to split the pipe using user interface.

I am trying achieve the same using the revit API.

Could you pls tell me is there any API to spcific to spli the Pipe.

i am new to this Revit API programming.

0 Likes
Message 4 of 17

jeremytammik
Autodesk
Autodesk

If you are new to the Revit API, the first thing to do is to work through the getting started material, especially the 'My First Revit Plug-in' and DevTV tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Getting started includes installing the SDK and RevitLookup, a very important Revit project database exploration tool.

 

Once you are up and running, take a look at The Building Coder and a discussion of this very question from quite a while back:

 

http://thebuildingcoder.typepad.com/blog/2012/03/split-a-duct-or-pipe.html

 

Please let us know how you get on with this.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 17

jeremytammik
Autodesk
Autodesk

Dear Ollikat,

 

Thank you for pointing out the other related forum discussion threads!

 

Looking through them all, I do not really see an easy starting point for a beginner.

 

Do you happen to have a snippet of sample code handly?

 

I will happily clean it up and republish it for you  🙂

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 17

ollikat
Collaborator
Collaborator
Hi Jeremy!

Yes...true...a bit challenging for total neewbie :-).

Well...bummer...unfortunately I don't have anything to publish. Obviously we do have code for this task, but it's done utilizing our own higher level classes and thus doesn't provide any value here :-(.
0 Likes
Message 8 of 17

Anonymous
Not applicable

Thank you Jeremy.

0 Likes
Message 9 of 17

Anonymous
Not applicable

Hi,

 

This is the pipe

 

start point--------------|-------------------endpoint

 

Now we want break the pipe at the point of the vertical line we can do so by:

 

Create a new pipe from start point to vertical line and the second line from vertical line to end point.

 

And then connect them.

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 10 of 17

Anonymous
Not applicable

Hi,

 

Could you pls suggest me how to find the length of pipe using Revit API?

I am using CURVE_ELEM_LENGTH but, it is not showing the length.

 

My requirement is like, i have to find the length of the pipe if it is more than the defined length is have to insert the coupling there.

Please suggest me.

 

 

0 Likes
Message 11 of 17

ollikat
Collaborator
Collaborator

Hi

Yeah. Actually you even have alternatives 😉

First (and maybe a bit more straightforward) is to get the pipe element's location curve. You can access it by using Element.Location property. It returns object of type Location, which is a base class of LocationCurve. Because you are dealing with the pipe element, the actual type of this object is LocationCurve and thus you can get it by casting the Location object.

From LocationCurve object you can access the Curve property which in turns offers an interface getting the length.

Second alternative is to get the end connectors of the pipe element and calculate the distance. You can access the pipe connectors trough the Pipe.ConnectorManager object. When you have correct connector objects in your hands, you can use Connector.Origin properties and use XYZ.DistanceTo() method.

Maybe there's an suitable parameter also somewhere, but these technicues are more robust because they work for all rigid curve elements. Very often you encounter built in parameters, that are valid only for certain category.

0 Likes
Message 12 of 17

jeremytammik
Autodesk
Autodesk

I always prefer using the geometry, just like you suggest.

 

For the splitting operation, here is a whole series of discussions on The Building Coder on implementing a Rolling Offset that should fit the bill and more:

 

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 13 of 17

Anonymous
Not applicable

Hi Jeremy,

 

I have a single pipe, suppose pipe lenght is some 5000mm, i have to divede that pipe exactly at 1000mm, and i have to insert coupling over there.

To inset coupling it needs 2 connectors. I am trying with the below code. If i have 2 parallel pipes then its adding coupling over.

I have just edited your code, as you suggested and shared in previous link.

 

Could you please guide me how to do the same over single pipe. And i have to divide the pipe exactly at 1000mm.

  

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)

{

 UIApplication uiapp = commandData.Application;

 UIDocument uidoc = uiapp.ActiveUIDocument;

 Application app = uiapp.Application;

 Document doc = uidoc.Document;

Autodesk.Revit.Creation.Document creDoc = doc.Create;

  

// Select all pipes in the entire model.

 List<Pipe> pipes = new List<Pipe>(new FilteredElementCollector(doc).OfClass(typeof(Pipe)).ToElements().Cast<Pipe>());

 int n = pipes.Count;

 

// If there are less than two,

// there is nothing we can do.

if (2 > n)

{

message = _prompt;

return Result.Failed;

}

 

// If there are exactly two, pick those.

if (2 < n)

{

// Else, check for a pre-selection.

pipes.Clear();

Selection sel = uidoc.Selection;

n = sel.Elements.Size;

TaskDialog.Show("{0} pre-selected elements.","");

// If two or more model pipes were pre-

// selected, use the first two encountered.

if (1 < n)

{

foreach (Element e in sel.Elements)

{

Pipe c = e as Pipe;

if (null != c)

{

pipes.Add(c);

if (2 == pipes.Count)

{

Console.WriteLine("Found two model pipes, "+ "ignoring everything else.");

break;

}

}

}

}

// Else, prompt for an

// interactive post-selection.

if (2 != pipes.Count)

{

pipes.Clear();

try

{

Reference r = sel.PickObject(ObjectType.Element,new PipeElementSelectionFilter(),"Please pick first pipe.");

pipes.Add(doc.GetElement(r.ElementId)as Pipe);

}

 catch (Autodesk.Revit.Exceptions.OperationCanceledException)

{

 return Result.Cancelled;

}

 try

{

 Reference r = sel.PickObject(ObjectType.Element,new PipeElementSelectionFilter(),"Please pick second pipe.");

pipes.Add(doc.GetElement(r.ElementId)as Pipe);

}

 catch (Autodesk.Revit.Exceptions.OperationCanceledException)

{

 return Result.Cancelled;

}

}

}

 // Extract data from the two selected pipes.

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

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

 if (!(c0 is Line) || !(c1 is Line))

{

message = _prompt+" Expected straight pipes.";

 return Result.Failed;

}

 XYZ p00 = c0.GetEndPoint(0);

 XYZ p01 = c0.GetEndPoint(1);

 

XYZ p10 = c1.GetEndPoint(0);

XYZ p11 = c1.GetEndPoint(1);

 

XYZ v0 = p01 - p00;

XYZ v1 = p11 - p10;

 

// Select the two pipe endpoints that are

// farthest apart.

 

XYZ p0 = p00.DistanceTo(p10) > p01.DistanceTo(p10)? p00: p01;

XYZ p1 = p10.DistanceTo(p0) > p11.DistanceTo(p0)? p10: p11;

 

XYZ pm = 0.5 * (p0 + p1);

XYZ v = p1 - p0;

 

String len = null;

len = pipes[0].get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsValueString();

TaskDialog.Show("revit", len);

  

XYZ z = v.CrossProduct(v1);

XYZ w = z.CrossProduct(v1).Normalize();

 

// Offset distance perpendicular to pipe direction

double distanceAcross = Math.Abs(v.DotProduct(w));

 // Distance between endpoints parallel

 // to pipe direction

double distanceAlong = Math.Abs(v.DotProduct(v1.Normalize()));

double angle = 45 * Math.PI / 180.0;

 // The angle on the other side.

double angle2 = 0.5 * Math.PI - angle;

double length = distanceAcross * Math.Tan(angle2);

double halfLength = 0.5 * length;

// How long should the pipe stubs become?

double remainingPipeLength= 0.5 * (distanceAlong - length);

 if (0 > v1.DotProduct(v))

{

v1.Negate();

}

v1 = v1.Normalize();

XYZ q0 = p0 + remainingPipeLength * v1;

 XYZ q1 = p1 - remainingPipeLength * v1;

  

using (Transaction tx = new Transaction(doc))

{

tx.Start("Rolling Offset");

 //// Trim or extend existing pipes

(pipes[0].Locationas LocationCurve).CurveLine.CreateBound(p0, q0);

(pipes[1].Locationas LocationCurve).Curve=Line.CreateBound(p1, q1);

 

 Connector pipe_start = null;

 Connector pipe_end = null;

  

double dist = double.MaxValue;

 foreach (Connector c in pipes[0].ConnectorManager.Connectors)

{

 XYZ p = c.Origin;

 double d = p.DistanceTo(q0);

 if (d < dist)

{

dist = d;

pipe_start = c;

}

 break;

}

 foreach (Connector conn in pipes[1].ConnectorManager.Connectors)

{

 if (conn.Origin.IsAlmostEqualTo(q1))

{

pipe_end = conn;

}

}

 FamilyInstance takeoff = creDoc.NewUnionFitting(pipe2_start, pipe2_end);

tx.Commit();

}

}

 

 

return Result.Succeeded;

}

}

 

0 Likes
Message 14 of 17

jeremytammik
Autodesk
Autodesk

Dear Anusha,

 

I feel I have done more than enough to support this effort.

 

I do not understand what is stopping you from finishing this off yourself.

 

Can you explain what the problem is?

 

Thank you!

 

By the way, here is another link on creating pipes and connectors:

 

http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/Revit-API/files/GUID-0...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 15 of 17

Anonymous
Not applicable

Hi Jeremy,

 

Thanks for your reply.

 

Issue i am facing is i have 5000mm length pipe. I have to divide the pipe exactly at 1000mm. and need to insert coupling.

I am not getting how to divede the pipe exactly at the 1000mm.

 

And i am completely new to this Revit API, and Mechanical stuffs.

 

0 Likes
Message 16 of 17

jeremytammik
Autodesk
Autodesk

Ollikat already answered your question, and I provided samples on how to implement it.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 17 of 17

jainn
Advocate
Advocate

Hi Anusha,

 

First get the start and end point of Pipe, from start point redraw pipe of desired lengths and then try to insert coupling. after that delete old pipe

 

 

Example

 

suppose you have pipe whose length is 500mm  and you want to place coupling at 100mm.

Draw five pipe of 100mm  in same direction and the try to insert coupling between pipes.

 

 

Regards

Namit

 

 

 

 

 

 

 

0 Likes