FamilyItemFactory.NewSweep
Description:
Adds a new sweep form to the family document, using a path of curve elements.
Adds a new sweep form to the family document, using a path of curve elements.
Remarks:
This method creates a sweep in a family document. The sweep will trace the profile along the path.
This method creates a sweep in a family document. The sweep will trace the profile along the path.
Overloads (2):
NewSweep(Boolean,CurveArray,SketchPlane,SweepProfile,Int32,ProfilePlaneLocation)
public Sweep NewSweep(
bool isSolid,
CurveArray path,
SketchPlane pathPlane,
SweepProfile profile,
int profileLocationCurveIndex,
ProfilePlaneLocation profilePlaneLocation
)
-
BooleanisSolidIndicates if the Sweep is Solid or Void.
-
pathThe path of the sweep. The path should be 2D, where all input curves lie in one plane, and the curves are not required to reference existing geometry.
-
pathPlaneThe sketch plane for the path. Use this when you want to create a 2D path that resides on an existing planar face. Optional, can be null for 3D paths or for 2D paths where the path should not reference an existing face.
-
profileThe profile of the newly created Sweep. This may contain more than one curve loop or a profile family. The profile must lie in the XY plane, and it will be transformed to the profile plane automatically. Each loop must be a fully closed curve loop and the loops must not intersect. The loop can be a unbound circle or ellipse, but its geometry will be split in two in order to satisfy requirements for sketches used in extrusions.
-
Int32profileLocationCurveIndexThe index of the path curves. The curve upon which the profile plane will be determined.
-
profilePlaneLocationThe location on the profileLocationCurve where the profile plane will be determined.
Return Value
Sweep
If creation was successful the new Sweep is returned,
otherwise an exception with failure information will be thrown.
private Sweep CreateSweep(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
{
Sweep sweep = null;
// make sure we have a family document
if (true == document.IsFamilyDocument)
{
// Define a profile for the sweep
CurveArrArray arrarr = new CurveArrArray();
CurveArray arr = new CurveArray();
// Create an ovoid profile
XYZ pnt1 = new XYZ(0, 0, 0);
XYZ pnt2 = new XYZ(2, 0, 0);
XYZ pnt3 = new XYZ(1, 1, 0);
arr.Append(Arc.Create(pnt2, 1.0d, 0.0d, 180.0d, XYZ.BasisX, XYZ.BasisY));
arr.Append(Arc.Create(pnt1, pnt3, pnt2));
arrarr.Append(arr);
SweepProfile profile = document.Application.Create.NewCurveLoopsProfile(arrarr);
// Create a path for the sweep
XYZ pnt4 = new XYZ(10, 0, 0);
XYZ pnt5 = new XYZ(0, 10, 0);
Curve curve = Line.CreateBound(pnt4, pnt5);
CurveArray curves = new CurveArray();
curves.Append(curve);
// create a solid ovoid sweep
sweep = document.FamilyCreate.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start);
if (null != sweep)
{
// move to proper place
XYZ transPoint1 = new XYZ(11, 0, 0);
ElementTransformUtils.MoveElement(document, sweep.Id, transPoint1);
}
else
{
throw new Exception("Failed to create a new Sweep.");
}
}
else
{
throw new Exception("Please open a Family document before invoking this command.");
}
return sweep;
}
-
Thrown when the input argument-path-isor empty.
-
Thrown when the input argument-profile-is.
-
Thrown when the input argument-profileLocationCurveIndex-is out of index bounds.
-
Thrown when the input argument-profilePlaneLocation-does not exist in the ProfilePlaneLocation enumeration.
-
Thrown when creation is attempted in Conceptual Mass, 2D, or other family where sweeps cannot be created.
-
Thrown when the creation failed.