Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

centerline

3 REPLIES 3
Reply
Message 1 of 4
revitworkbench
970 Views, 3 Replies

centerline

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.

3 REPLIES 3
Message 2 of 4
Aaron.Lu
in reply to: revitworkbench

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.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 3 of 4
revitworkbench
in reply to: Aaron.Lu

Can this operation be done in a 3D view? I use mostly 3D views. thanks!

Message 4 of 4
Aaron.Lu
in reply to: revitworkbench

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.



Aaron Lu
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report