RevitAPI: 調用NewExtrusion的時候拋出異常 One of the conditions for the inputs was not satisfied

當調用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));


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章