Is there a way to pick the center line of a pipe or duct in the revit API? I am trying to think of a way to write a macro to align 2 "pipes" via their centerlines by simply clicking one, and then the other. I know you can do it using the align tool but its tedious to tab select the centerline, especially when there is insulation involve. Thanks in advance.
Dear Mike Mead, We can align centerlines of pipes using API, here is how to do this:
- get the pipe elements
- retrieve center line geometry from the pipes, note: options's property IncludeNonVisibleObjects and ComputeReferences should be set to true. and the View should be set to the plan view, here I assume ActiveView is a plan view.
Options options = new Options(); options.ComputeReferences = true; if (pipe.Document.ActiveView != null) options.View = pipe.Document.ActiveView; else options.DetailLevel = ViewDetailLevel.Fine; options.IncludeNonVisibleObjects = true; var geoElem = pipe.get_Geometry(options);
- and get the centerline, which is Line
foreach (var item in geoElem) { Line lineObj = item as Line; if (lineObj != null) { // } }
- Move one pipe to align with the other, using ElementTransformUtils.MoveElement, this is a must
- Get reference from the geometry lines and Create the alignment constraint using RevitDoc.Create.NewAlignment method.
Unfortunately, I tried but failed with an exception:
Autodesk.Revit.Exceptions.InternalException: Unexpected internal error: code 1.
In UI we can't do that either, so I should vote for infeasible to do this in 3D view.
Can't find what you're looking for? Ask the community or share your knowledge.