How to crete 3D modelCurves to avoid exception 'curve must be in the plane' ?

How to crete 3D modelCurves to avoid exception 'curve must be in the plane' ?

Anonymous
Not applicable
2,793 Views
2 Replies
Message 1 of 3

How to crete 3D modelCurves to avoid exception 'curve must be in the plane' ?

Anonymous
Not applicable

Hi!

I want to create new group of lines (3d). My code looks like:

List<ElementId> setOfLines = new List<ElementId>();
for (var i = 0; i < Points.Length - 1; i++) { Line line = Line.CreateBound(Points[i], Points[i + 1]); XYZ normal = line.Direction.Normalize(); Plane plane = Plane.CreateByNormalAndOrigin(normal, Points[i]); SketchPlane sketchPlane = SketchPlane.Create(CurrentRevitDocument, plane); ModelCurve modelCurve = CurrentRevitDocument.Create.NewModelCurve(line, sketchPlane); setOfLines.Add(modelCurve. Id); } CurrentRevitDocument.Create.NewGroup(setOfLines);

But i have an exception "curve must be in the plane, pCurveCopy".

I think this is because of the coordinates of the normal, they are wrong. How can i create my 3D modelCurves right? Should I use another methods for this?

Thanks for your help.

0 Likes
Accepted solutions (1)
2,794 Views
2 Replies
Replies (2)
Message 2 of 3

BardiaJahan
Advocate
Advocate
Accepted solution

It seems the normal of your sketch plane is parallel to your line. This means the line is definitely not in that plane. For the normal, you should use a vector that is perpendicular to the line so that the line lies in the plane.

Basically if XYZ n is the normal then n.DotProduct(line.Direction) must be zero.

Now I propose these two options:

1- You could use any arbitrary vector XYZ v that is not parallel to your line and use XYZ u = v.CrossProduct(line.Direction) as the normal of your sketch plane. For simplicity, v could be one of the basis vectors - e.g. XYZ.BasisZ as long as it is not parallel to your line. (a simple if-else) => XYZ.BasisZ.CrossProduct(line.Direction)

2- Or as I prefer construct vector n as following and use it as the normal:

XYZ dir = line.Direction;
double x = dir.X, y = dir.Y, z = dir.Z;
XYZ n = new XYZ (z - y, x - z, y - x);

 

Message 3 of 3

Anonymous
Not applicable

Thank you very much for your help!