Issue
I created a very simple sweep solid with a simple rectangular profile on a xy-plane, sweeping along z-axis. However, depending on the sketch plane I used (e.g., xz-plane or yz-plane), the results are different. Why is that?
The following code demonstrates my problem.
public void CreateSweep()
{
Transaction trans = new Transaction(m_rvtDoc, "Sweep");
trans.Start();
SweepProfile profile = CreateSweepProfile();
// (1) the path plane is xz-plane
// Plane(normal, origin)
Plane plane1 =
new Plane(new XYZ(0, 1, 0), new XYZ(0, 0, 0));
SketchPlane sketchPlane1 =
m_rvtDoc.FamilyCreate.NewSketchPlane(plane1);
Lineline1 = m_rvtApp.Create.NewLineBound(
new XYZ(0, 0, 0), new XYZ(0, 0, 1));
ModelCurve mLine1 = m_rvtDoc.FamilyCreate.NewModelCurve(
line1, sketchPlane1);
CurveArray pathArray1 = new CurveArray();
pathArray1.Append(line1);
m_rvtDoc.FamilyCreate.NewSweep(
true, pathArray1, sketchPlane1,
profile, 0, ProfilePlaneLocation.Start);
// (2) the path plane is yz-plane
Plane plane2 = new Plane(
new XYZ(1, 0, 0), new XYZ(0, 0, 0));
SketchPlane sketchPlane2 =
m_rvtDoc.FamilyCreate.NewSketchPlane(plane2);
Line line2 = m_rvtApp.Create.NewLineBound(
new XYZ(0, 0, 0), new XYZ(0, 0, 2));
ModelCurve mLine2 = m_rvtDoc.FamilyCreate.NewModelCurve(
line2, sketchPlane2);
CurveArray pathArray2 = new CurveArray();
pathArray2.Append(line2);
m_rvtDoc.FamilyCreate.NewSweep(
true, pathArray2, sketchPlane2,
profile, 0, ProfilePlaneLocation.Start);
trans.Commit();
}
private SweepProfile CreateSweepProfile()
{
XYZ pt1 = new XYZ(0, 0, 0);
XYZ pt2 = new XYZ(10, 0, 0);
XYZ pt3 = new XYZ(10, 20, 0);
XYZ pt4 = new XYZ(0, 20, 0);
Line line1 = m_rvtApp.Create.NewLineBound(pt1, pt2);
Line line2 = m_rvtApp.Create.NewLineBound(pt2, pt3);
Line line3 = m_rvtApp.Create.NewLineBound(pt3, pt4);
Line line4 = m_rvtApp.Create.NewLineBound(pt4, pt1);
CurveArray curArray = new CurveArray();
curArray.Append(line1);
curArray.Append(line2);
curArray.Append(line3);
curArray.Append(line4);
CurveArrArray curArrArray = new CurveArrArray();
curArrArray.Append(curArray);
SweepProfile result =
m_rvtApp.Create.NewCurveLoopsProfile(curArrArray);
return result;
}
Solution
This is actually "as designed" behavior. Even though mathematically it does look like both should produce the same result, the behavior of this function is analogous to the UI's; i.e., the profile's coordinate system is defined at the starting point of path, where the direction of the path is the z-axis, and sketch plane's normal is y-direction.
In the above example, the first one uses the same coordinate for both profile and sweep, while the second one will take z-direction as z-axis (the direction of path), and x-direction as y-axis of sweep (as defined as a normal of the sketch plane), resulting that the profile will be rotated.