As the post title explains, in this short post we shall take a look at a not-so-obvious rule for input profiles in the NewSweptBlend method. This is based on one of the queries that we have received from a partner in the recent past.
The following method CreateNewSweptBlend based on the GenericModelCreation SDK sample CreateGenericModel method creates a valid swept blend form:
public void CreateNewSweptBlend(Document doc)
{
if (!doc.IsFamilyDocument)
{
TaskDialog.Show("Error",
"Please run this command in a family document.");
}
Autodesk.Revit.ApplicationServices.Application app = doc.Application;
Autodesk.Revit.Creation.Application creapp
= app.Create;
CurveArrArray curvess0
= creapp.NewCurveArrArray();
CurveArray curves0 = new CurveArray();
XYZ p00 = creapp.NewXYZ(0, 7.5, 0);
XYZ p01 = creapp.NewXYZ(0, 15, 0);
// changing Z to 1 in the following line fails:
XYZ p02 = creapp.NewXYZ(-1, 10, 0);
curves0.Append(creapp.NewLineBound(p00, p01));
curves0.Append(creapp.NewLineBound(p01, p02));
curves0.Append(creapp.NewLineBound(p02, p00));
curvess0.Append(curves0);
CurveArrArray curvess1 = creapp.NewCurveArrArray();
CurveArray curves1 = new CurveArray();
XYZ p10 = creapp.NewXYZ(7.5, 0, 0);
XYZ p11 = creapp.NewXYZ(15, 0, 0);
// changing the Z value in the following line fails:
XYZ p12 = creapp.NewXYZ(10, -1, 0);
curves1.Append(creapp.NewLineBound(p10, p11));
curves1.Append(creapp.NewLineBound(p11, p12));
curves1.Append(creapp.NewLineBound(p12, p10));
curvess1.Append(curves1);
SweepProfile sweepProfile0
= creapp.NewCurveLoopsProfile(curvess0);
SweepProfile sweepProfile1
= creapp.NewCurveLoopsProfile(curvess1);
XYZ pnt10 = new XYZ(5, 0, 0);
XYZ pnt11 = new XYZ(0, 20, 0);
Curve curve = creapp.NewLineBound(pnt10, pnt11);
XYZ normal = XYZ.BasisZ;
SketchPlane splane = CreateSketchPlane(
doc, normal, XYZ.Zero);
try
{
SweptBlend sweptBlend = doc.FamilyCreate.NewSweptBlend(
true, curve, splane, sweepProfile0, sweepProfile1);
}
catch (Exception ex)
{
Util.ErrorMsg("NewSweptBlend exception: " + ex.Message);
}
return;
}
But if we change the Z coordinate value of points p02 and p12 to 1 instead of 0, it throws an invalid operation exception. Which rule is being broken when I change the Z value of both p02 and p12, please? Does the curve have to be perpendicular to the sweep profiles?
The problem is neither in the user interface nor the API, but simply in the definition of the input curves and the NewSweptBlend method documentation. The Revit API help file RevitAPI.chm states the following requirements for the two input profiles bottomProfile and topProfile:
- Type: Autodesk.Revit.DB.SweepProfile.
- It should consist of only one curve loop.
- The input profile must be in one plane.
After some research and discussion, we determined that the input profile curve loop must be in the XY plane, implying that the Z coordinates must all be zero. Revit will calculate the profile planes with the input path curve and then transforms the XY plane curve loop to the right profile plane internally. In other words, you need to define the curve profiles to be 2D and located in the XY plane, i.e. set the XYZ input points' Z coordinates to zero. Unfortunately, the documentation does not mention the XY plane, it just states that the curves should be in one plane. Once we set all the Z coordinates to zero, it works fine.