I was recently looking for NewSweptBlend code sample. But I found very little. Here it is one hopefully help you understand the basics of NewSweptBlend usage. The code creates two solids with swept blend operations: one with spline and the other with arc as a path. They both have a triangular profile. An image is attached at the bottom.
// SweptBlend with spline and arc path
[Transaction(TransactionMode.Manual)]
public class rvtCmd_SweptBlendWithSplinePath : IExternalCommand
{
// member variables
Application m_rvtApp;
Document m_rvtDoc;
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// get the access to the top most objects.
UIApplication rvtUIApp = commandData.Application;
UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
m_rvtApp = rvtUIApp.Application;
m_rvtDoc = rvtUIDoc.Document;
CreateSweptBlend_SplinePath();
CreateSweptBlend_ArcPath();
return Result.Succeeded;
}
public void CreateSweptBlend_SplinePath()
{
Transaction trans =
new Transaction(m_rvtDoc, "Create SweptBlend");
trans.Start();
// Create a path
Curve path1 = CreatePathSpline();
// sketch plane of path
Plane plane1 = new Plane(XYZ.BasisY, new XYZ(0, 0, 0));
SketchPlane sketchPlane1 =
m_rvtDoc.FamilyCreate.NewSketchPlane(plane1);
double dt = 10.0;
Plane plane2 =
new Plane(-XYZ.BasisX, new XYZ(2 * dt, 0, 0));
SketchPlane sketchPlane2 =
m_rvtDoc.FamilyCreate.NewSketchPlane(plane2);
// Create a profile. Using the same one
SweepProfile profile1 = CreateProfileTriangle1();
SweepProfile profile2 = CreateProfileTriangle1();
// create swept blend
m_rvtDoc.FamilyCreate.NewSweptBlend(
true, // isSolid
path1, // path
sketchPlane1, // path plane
profile1, // bottom profile
profile2 // top profile
);
trans.Commit();
}
public void CreateSweptBlend_ArcPath()
{
Transaction trans =
new Transaction(m_rvtDoc, "Create SweptBlend");
trans.Start();
// create a path
Arc path2 = CreatePathArc2();
// coordinate of profile
double param0 = path2.get_EndParameter(0);
Transform t = path2.ComputeDerivatives(param0, true);
XYZ zDir = t.BasisX;
XYZ yDir = path2.Normal;
XYZ xDir = yDir.CrossProduct(zDir);
// path plane
Plane plane2 = new Plane(path2.Normal, t.Origin);
SketchPlane sketchPlane2 =
m_rvtDoc.FamilyCreate.NewSketchPlane(plane2);
// Create a profile. using the same one
SweepProfile profile3 = CreateProfileTriangle2();
SweepProfile profile4 = CreateProfileTriangle2();
// The second path
m_rvtDoc.FamilyCreate.NewSweptBlend(
true, // isSolid
path2, // path
sketchPlane2, // path plane
profile3, // bottom profile
profile4 // top profile
);
trans.Commit();
}
// a path with an arc of 90 degree angle on xz-plane
//
private Curve CreatePathSpline()
{
List<XYZ> ctrlPoints = new List<XYZ>();
XYZ p0 = new XYZ(0, 0, 0);
XYZ p1 = new XYZ(0, 0, 6);
XYZ p2 = new XYZ(4, 0, 5);
XYZ p3 = new XYZ(7, 0, 3);
XYZ p4 = new XYZ(10, 0, 3);
XYZ p5 = new XYZ(10, 0, 5);
ctrlPoints.Add(p0);
ctrlPoints.Add(p1);
ctrlPoints.Add(p2);
ctrlPoints.Add(p3);
ctrlPoints.Add(p4);
ctrlPoints.Add(p5);
List<double> weights = new List<double>();
double w1 = 1, w2 = 1, w3 = 1, w4 = 1, w5 = 1, w6 = 1;
weights.Add(w1); weights.Add(w2); weights.Add(w3);
weights.Add(w4); weights.Add(w5); weights.Add(w6);
NurbSpline spline =
m_rvtApp.Create.NewNurbSpline(ctrlPoints, weights);
return spline;
}
// a path with an arc of 90 degree angle on
// a plane parallel to yz-plane
//
private Arc CreatePathArc2()
{
double dt = 5;
XYZ center = new XYZ(2 * dt, dt, dt);
double r = dt;
double startAngle = 0.0;
double endAngle = Math.PI / 2.0;
Arc Arc1 = m_rvtApp.Create.NewArc(
center, r,
startAngle, endAngle,
-XYZ.BasisY, XYZ.BasisZ);
return Arc1;
}
private SweepProfile CreateProfileTriangle1()
{
XYZ pt0 = new XYZ(0, 0, 0);
XYZ pt1 = new XYZ(1, 0, 0);
XYZ pt2 = new XYZ(0, 2, 0);
Line line1 = m_rvtApp.Create.NewLineBound(pt0, pt1);
Line line2 = m_rvtApp.Create.NewLineBound(pt1, pt2);
Line line3 = m_rvtApp.Create.NewLineBound(pt2, pt0);
CurveArray curArray = new CurveArray();
curArray.Append(line1);
curArray.Append(line2);
curArray.Append(line3);
CurveArrArray curArrArray = new CurveArrArray();
curArrArray.Append(curArray);
SweepProfile result =
m_rvtApp.Create.NewCurveLoopsProfile(curArrArray);
return result;
}
// this is for the second arc
private SweepProfile CreateProfileTriangle2()
{
// this is the target.
XYZ pt0 = new XYZ(0, 0, 0);
XYZ pt1 = new XYZ(2, 0, 0);
XYZ pt2 = new XYZ(0, -1, 0);
Line line1 = m_rvtApp.Create.NewLineBound(pt0, pt1);
Line line2 = m_rvtApp.Create.NewLineBound(pt1, pt2);
Line line3 = m_rvtApp.Create.NewLineBound(pt2, pt0);
CurveArray curArray = new CurveArray();
curArray.Append(line1);
curArray.Append(line2);
curArray.Append(line3);
CurveArrArray curArrArray = new CurveArrArray();
curArrArray.Append(curArray);
SweepProfile result =
m_rvtApp.Create.NewCurveLoopsProfile(curArrArray);
return result;
}
}