当调用Document.FamilyCreate.NewExtrusion的时候,可能会抛出下面的异常
Autodesk.Revit.Exceptions.ArgumentException: One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument.
这个很有可能是因为您传入的profile和normal不垂直,也就是形状和拉伸方向不垂直。
例如自己的代码可能是这么写的:
// Create a rectangle profile
CurveArrArray profile = new CurveArrArray();
CurveArray ca = new CurveArray();
XYZ[] points = new XYZ[] {
new XYZ(10, 0, 0),
new XYZ(20, 0, 0),
new XYZ(20, 0, 10),
new XYZ(10, 0, 10)
};
for (int ii = 0; ii < points.Length; ii++)
{
var point = points[ii];
var point2 = points[ii == points.Length - 1 ? 0 : ii + 1];
ca.Append(Line.CreateBound(point, point2));
}
profile.Append(ca);
// create the plane normal is perpendicular with profile
SketchPlane sketchplane = SketchPlane.Create(doc,
new Plane(XYZ.BasisZ, XYZ.Zero));
Extrusion solid = doc.FamilyCreate.NewExtrusion(
true, profile, sketchplane, 20);
实际上注意到SketchPlane的normal是向上的也就是和Z轴垂直,而profile和Y轴垂直,
所以,创建SketchPlane的代码应该是这样的:
SketchPlane sketchplane = SketchPlane.Create(doc,
new Plane(XYZ.BasisY, XYZ.Zero));