我有一个用C#编写的Revit插件的代码:
namespace CreateFloors
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
FilteredElementCollector levels
= new FilteredElementCollector(doc)
.OfClass(typeof(Level));
FloorType floorType
= new FilteredElementCollector(doc)
.OfClass(typeof(FloorType))
.First<Element>(
e => e.Name.Equals("Generic - 12\""))
as FloorType;
Element profileElement
= new FilteredElementCollector(doc)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_GenericModel)
.First<Element>(
e => e.Name.Equals("WP1"));
CurveArray slabCurves = new CurveArray();
GeometryElement geo = profileElement.get_Geometry(new Options());
foreach (GeometryInstance inst in geo)
{
foreach (GeometryObject obj in inst.SymbolGeometry)
{
if (obj is Curve)
{
slabCurves.Append(obj as Curve);
}
}
}
XYZ normal = XYZ.BasisZ;
Transaction trans = new Transaction(doc);
trans.Start("Create Floors");
foreach (Level level in levels)
{
Floor newFloor = doc.Create.NewFloor(slabCurves, floorType, level, false, normal);
newFloor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0);
}
trans.Commit();
return Result.Succeeded;
}
}
}
当我从包含通用模型的Revit项目中跟踪此代码时,抛出下一个异常:
Autodesk.Revit.Exceptions.ArgumentException:'曲线不会形成封闭的连续循环。
我的结构是连续的。我该如何解决这个问题?
答案 0 :(得分:1)
您的曲线可能未按正确的连续顺序排序。
您可以实现一些图形调试显示,逐条显示曲线作为模型线,并在每个曲线旁边添加一个数字,以查看您实际拥有的顺序。
以下是The Building Coder在Sorting Face Loop Edges上的讨论。