I am trying to place a pipe precisely between two points: intersectionPoint and intersectionPoint + perpendicularDirection. I am using the following statement to move the pipe:
Pipe dummyPipe = doc.GetElement(ElementTransformUtils.CopyElement(doc, branchPipe.Id, XYZ.Zero).First()) as Pipe; (dummyPipe.Location as LocationCurve).Curve = Line.CreateBound(intersectionPoint, intersectionPoint + 1.0 * perpendicularDirection);
With the above placement, I would expect the pipe's curve's direction to be exactly equal to perpendicularDirection. But that's not the case. As an example, if perpendicularDirection is set to {(-0.016831296, 0.968685013, -0.052781984)}, the direction of the pipe comes out to be {(-0.017347059, 0.998368562, -0.054399389)}. Note that there is a slight difference in the direction and as a result, I am not able to connect this pipe to a Tee fitting as per Insert T-connection.
BTW the same issue happens even if I create a new pipe between two points.
Any idea how to fix this issue?
In most cases, you do not need to specify an exact pipe direction to create a pipe between fittings, not an exact fitting location to insert a fitting between existing pipes.
Revit will automatically adjust the newly created element appropriately to connect with the existing elements.
I discovered this and explored it in some detail in my research series on creating a rolling offset:
http://thebuildingcoder.typepad.com/blog/2014/01/final-rolling-offset-using-pipecreate.html
Please study the different approaches presented in that research series.
I hope this helps.
Best regards,
Jeremy
@jeremytammik The problem was because of inaccuracy in the cross product. I was deriving the pipe direction by doing two cross-products of unit-norm vectors. In other words, pipeDirection = X.CrossProduct(Y).CrossProduct(X). If X and Y are of unit-norm, I would expect pipeDirection to be unit-norm, but that wasn't the case. I was getting about 0.971 instead of 1.000. I thought that Revit uses doubles and not floats, but may be that's not the case. Once I normalize pipeDirection, it worked fine.
BTW Your rolling offset post only deals with inserting elbows, which works pretty well. In my case, I am inserting T connection and that API is a horrible mess. Here are the issues:
This issue along with Line based family location don't update Origin after change has taken me about a week to create a T connection at the right place and orientation instead of probably an hour if the API had worked in the first place.
Thank you very much for your research, solution, and pointers to the other issues.
Sorry to hear that it cost you so much time to resolve these issues.
I am glad to hear that you succeeded in the end. Congratulations!
This all seems very useful to me, so I'll summarise it on The Building Coder for future reference.
One little clarification:
If X and Y are both unit length, their cross product will still NOT be unit length unless they are exactly perpendicular.
Best regards,
Jeremy