private CurveArray CreatecustomCoverProfile(double offset) { // the following code worked // Arc arc1 = Arc.Create(new XYZ(0, 0, 0), 5, Math.PI / 2, Math.PI * 3 / 2, XYZ.BasisX, XYZ.BasisY); // Line line = Line.CreateBound(new XYZ(0, 5, 0), new XYZ(0, -5, 0)); // CurveArray curveArr = new CurveArray(); // curveArr.Append(arc); // curveArr.Append(line); // the following code failed XYZ center1 = new XYZ(0, 0, 0); XYZ center2 = new XYZ(10, 0, 0); Arc arc1 = Arc.Create(center1, 5, Math.PI / 2, Math.PI * 3 / 2, XYZ.BasisX, XYZ.BasisY); Arc arc2 = Arc.Create(center2, 5, Math.PI * 3 / 2, Math.PI * 5 / 2, XYZ.BasisX, XYZ.BasisY); Line line1 = Line.CreateBound(new XYZ(0, 5, 0), new XYZ(10, 5, 0)); Line line2 = Line.CreateBound(new XYZ(0, -5, 0), new XYZ(10, -5, 0)); CurveArray curveArr = new CurveArray(); curveArr.Append(arc1); curveArr.Append(line1); curveArr.Append(arc2); curveArr.Append(line2); return curveArr; } private bool CreateSweep(Document famDoc) { Family family = famDoc?.OwnerFamily; if (null == family) return false; Collection<XYZ> points = CreateCablePoints(); if (points.Count < 2) return false; using (Transaction trans = new Transaction(famDoc, "create cover")) { trans.Start(); // create profile CurveArrArray arArr = new CurveArrArray(); arArr.Append(CreatecustomCoverProfile(0)); SweepProfile profile = _rvApp.Create.NewCurveLoopsProfile(arArr); // create path // the path was created from a simple sine-like hermite spline with hardcode control points CurveArray path = CreatePath(points); // create sketch plane Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); SketchPlane pathPlane = SketchPlane.Create(famDoc, plane); Sweep cover = famDoc.FamilyCreate.NewSweep(true, path, pathPlane, profile, 0, ProfilePlaneLocation.Start); trans.Commit(); } return true; }
Solved! Go to Solution.
Solved by nam_vt. Go to Solution.
It seems, that the problem is in your curve loop. First arc ends at the point with coordinates: (0, -5, 0), but then you append a line, that starts from (0, 5, 0). Try to replace this:
curveArr.Append(arc1); curveArr.Append(line1); -> curveArr.Append(line2); curveArr.Append(arc2); curveArr.Append(line2); -> curveArr.Append(line1);
Thanks for the suggestion, but I believe that is not the case. I tried it with the "working" code and it works with either of my line 's direction. The "failed" code still does not work no matter what order I put my curves in the curve loop, or whether the curves directions conform the curve loop 's direction.
I just figure out why my code did not work: The size of the profile I created is too big that when it is swept along the path, the sweep did intersect itself. Thus the error occurred.
However, I wonder if there is a simple way for us dev to detect the problem programmatically instead of just manually calculate the sweep and scratch our heads until we come a cross this possibility randomly. An evaluate method when create sweep or an exception throw when commit to database would be nice. For now, I only receive unintuitive error message of Revit.
I am sorry to say that there is currently no API access to this functionality.
You can post your wish idea here to vote it: http://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent
Can't find what you're looking for? Ask the community or share your knowledge.