Autodesk Revit 参数异常,曲线不形成闭合连续环
Autodesk Revit Argument Exception, The curves do not form a closed contiguous loop
我有用 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: '曲线没有形成闭合的连续环。
我有一个连续的结构。我该如何解决这个问题?
您的曲线可能没有按正确的连续顺序排序。
您可以实现一些图形调试显示,将曲线一条一条地显示为模型线,并在每条曲线旁边添加一个数字以查看您实际拥有的顺序。
这是 The Building Coder 在 Sorting Face Loop Edges 上的讨论。
我有用 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: '曲线没有形成闭合的连续环。
我有一个连续的结构。我该如何解决这个问题?
您的曲线可能没有按正确的连续顺序排序。
您可以实现一些图形调试显示,将曲线一条一条地显示为模型线,并在每条曲线旁边添加一个数字以查看您实际拥有的顺序。
这是 The Building Coder 在 Sorting Face Loop Edges 上的讨论。