Rotate placed Element/Family to align with the endpoint of a pipe

Rotate placed Element/Family to align with the endpoint of a pipe

Chris-VC_Studio
Advocate Advocate
1,794 Views
7 Replies
Message 1 of 8

Rotate placed Element/Family to align with the endpoint of a pipe

Chris-VC_Studio
Advocate
Advocate

After successfully getting my Flow arrows to come into the model to match the pipe curve elevation, now I am trying to get the Flow arrow to align with to end point of the pipe using the ElementTransformUtils.RotateElement method. Currently, the arrows drop into the model in the same direction the flow arrow was created in, to the left no matter what angle or direction the pipe was created in. Any advice or help would be appreciated

 

My thoughts are to 

  1. get the end points of the pipe
  2. then get the pipe direction and normalize it
  3. Get the rotation axis
  4. get the angle 
  5. then use the ElementformsUtils method.

                //Code to create flow arrow on the Curve of the pipe

                var placedArrow = document.Create.NewFamilyInstance(point, flowArrow, document.GetElement(levelId) as Level, StructuralType.NonStructural);

                

                //Code to correct the insertion elevation of the object

                document.Regenerate();

                LocationPoint arrowLocationPoint = placedArrow.Location as LocationPoint;

                XYZ location = arrowLocationPoint.Point;

                XYZ differencePoint = new XYZ(point.X - location.X, point.Y - location.Y, point.Z - location.Z);

                placedArrow.Location.Move(new XYZ(differencePoint.X, differencePoint.Y, differencePoint.Z));

 

                //Rotate to match Pipe curve

                XYZ pipeStartPoint = pipeCurve.GetEndPoint(0);

                XYZ pipeEndPoint = pipeCurve.GetEndPoint(1);

                XYZ pipeDirection = (pipeEndPoint - pipeStartPoint).Normalize();

                Line rotationAxis = Line.CreateBound(pipeStartPoint, pipeEndPoint);

                double rotationAngle = pipeCurve.ComputeDerivatives(0, true).BasisZ.AngleOnPlaneTo(pipeEndPoint, pipeDirection);

                ElementTransformUtils.RotateElement(document, placedArrow.Id, rotationAxis, rotationAngle);

                

 

                transaction.Commit();

 

If you want to see the full code here is my gitHub page:

https://github.com/cabowker/FlowArrows

 

Also, I attached a 2023 model with flow-arrow family and pipe.

 

 

 

Accepted solutions (1)
1,795 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni

Dear Chris,

  

Have you researched the best practices for achieving this task? Revit provides a lot of powerful functionality built-in. I am not an expert in this area, so I do not know what the best practices might be. It seems to me that you are trying to solve things that ought to happen automatically. For instance, If I search for 'revit pipe place flow arrow', I see results that seem simpler and more effective than the approach you are attempting:

  

https://duckduckgo.com/?q=revit+pipe+flow+arrow+place

https://forums.autodesk.com/t5/revit-mep-forum/how-to-make-a-pipe-tag-with-flow-arrow/td-p/8032104

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 8

Songohu_85
Enthusiast
Enthusiast
Accepted solution

In order to align family instance direction with pipe direction on plan view you can create it with correct direction:

 

			Document doc = ActiveUIDocument.Document;
			Reference pipeReference = ActiveUIDocument.Selection.PickObject(ObjectType.Element);
			Pipe selectedPipe = doc.GetElement(pipeReference) as Pipe;
			Line line = (selectedPipe.Location as LocationCurve).Curve as Line;
			
			XYZ lineMidPoint = (line.GetEndPoint(0) + line.GetEndPoint(1))/2;
			XYZ direction = line.Direction;

			FamilySymbol fs = doc.GetElement(new ElementId(1363671)) as FamilySymbol;

			using (Transaction tx = new Transaction(doc, "Create instance")) 
			{
				tx.Start();
				doc.Create.NewFamilyInstance(lineMidPoint, fs, direction, doc.ActiveView, StructuralType.NonStructural);
				tx.Commit();
			}

 

 Unfortunatelly FLOW direction is something that according to my knowledge can not be obtained from a single pipe instance. You will have to analyse entire piping system, connector types of connected appliances, flow increase or dicrease. Edit: For sloped pipes it can be relatively easier.

Message 4 of 8

Chris-VC_Studio
Advocate
Advocate

Sweet, thank you Jeremy and Songohu for your help and advice.

 

Jeremy,

I already saw this post a few years ago and that's what inspired me to 2 create my original set of flow arrows as annotations for 2D drawings. Later I found that when I had to give presentations of rather large mechanical rooms it was much easier to have 3D arrows inside my pipe model so that I can better illustrate the direction of flow inside of Navisworks and that is what inspired me to create my 3D arrows and now this little plugin.

 

Songohu,

Thank you for the sample code I was able to adapt it into my code to get the arrows to align with the direction of the pipe; I never thought to do it during the placement of the arrows. I was mostly focused on getting it to rotate after placement, now all I have to do since it's rather difficult to get the flow directional of the pipe is to orientate the arrow during placement to align with the end point of the pipe Since I mostly draw and the direction of flow from the pumps to the chillers to the exchangers then to the building, but that will be a project for another day. Thank you once again for your help.

 

Message 5 of 8

Songohu_85
Enthusiast
Enthusiast

Hi, I'm glad to hear it was useful.

 

In the link below you can find PoC for piping system analysis. The solution implements simple Graph algorith to find all possible paths between two given elements. For your future developments: if you clearly define which element is a starting point and which are endpoints then the analysis of connectivity and eventually predicting flow direction will not be very difficult.

 

https://github.com/songohu30/PipingSystemPath

Message 6 of 8

Chris-VC_Studio
Advocate
Advocate

Wow, I will be sure to check it out.

Thank you Songohu, much appreciated.

 

And for anyone wanting to check out the code I have revised so far you can visit my GitHub repository at:

https://github.com/cabowker/FlowArrows

 

and the model with the Flow Arrows is attached

Message 7 of 8

reylorente1
Collaborator
Collaborator
Hello, your code is very interesting, and I'm trying to make it work completely, I just need to establish the window, and I think that's why you used this code

 private void SetOwner()
        {

            WindowHandleSearch search = WindowHandleSearch.MainWindowHandle;
            search.SetAsOwner(this);
        }

Could you provide the WindowHandleSearch class?
0 Likes