您的位置:首页 > 其它

RevitAPI: Rebar.CreateFromCurves抛出异常: Unable to create a RebarShape based on the given curves

2014-12-17 10:27 471 查看
我们知道通过Rebar提供几个创建的函数,其中一个是CreateFromCurves,

public static Rebar CreateFromCurves(
Document doc, RebarStyle style, RebarBarType barType,
RebarHookType startHook, RebarHookType endHook, Element host,
XYZ norm, IList<Curve> curves,
RebarHookOrientation startHookOrient,
RebarHookOrientation endHookOrient,
bool useExistingShapeIfPossible, bool createNewShape);


我们主要看norm和curves这两个参数,

norm

Type: XYZ

The normal to the plane that the rebar curves lie on.

curves

Type: IList<Curve>

An array of curves that define the shape of the rebar curves. They must belong to the plane defined by the normal and origin. Bends and hooks should not be included in the array of curves.
RevitAPI.chm文档显示,curves必须在norm定义的平面上。

有一个用户的代码如下,curves所在的面也和norm是垂直的。他想创建两个Rebar,结果却是第一个创建成功了,第二个却抛出异常InvalidOperationException: Unable to create a RebarShape based on the given curves.

或者有时候是这样的异常:

Revit encountered a Autodesk.Revit.Exceptions.InternalException: An internal error has occurred.

RebarBarType bartype = new FilteredElementCollector(RevitDoc)
.OfClass(typeof(RebarBarType))
.FirstOrDefault(t => t.Name == "8 HPB300") as RebarBarType;
Curve
curve = Line.CreateBound(
new XYZ(5.656152019023, 43.5912980314625, -10.0065608637852),
new XYZ(5.65615201724766, 43.5912980188303, 7.70997373826235));
curves.Add(curve);
curve = Line.CreateBound(
new XYZ(5.65615201724766, 43.5912980188303, 7.70997373826235),
new XYZ(5.65615201724766, 45.2478392340832, 7.70997373826235));
curves.Add(curve);
curve = Line.CreateBound(
new XYZ(5.65615201724766, 45.2478392340832, 7.70997373826235),
new XYZ(5.656152019023, 45.2478392467154, -10.0065608637852));
curves.Add(curve);

// Create succesfully!
Rebar.CreateFromCurves(RevitDoc, RebarStyle.Standard, bartype, null,
null, ele, nml, curves, RebarHookOrientation.Left,
RebarHookOrientation.Left, false, true);

// Problem Curves
List<Curve> curves2 = new List<Curve>();
curve = Line.CreateBound(
new XYZ(6.22700217574493, 43.5110702844365, -10.0065608637852),
new XYZ(6.22700217219427, 43.5110702591722, 7.70997373826235));
curves2.Add(curve);
curve = Line.CreateBound(
new XYZ(6.22700217219427, 43.5110702591722, 7.70997373826235),
new XYZ(6.22700217219427, 45.1676114744251, 7.70997373826235));
curves2.Add(curve);
curve = Line.CreateBound(
new XYZ(6.22700217219427, 45.1676114744251, 7.70997373826235),
new XYZ(6.22700217574493, 45.1676114996894, -10.0065608637852));
curves2.Add(curve);
//InvalidOperationException thrown
//  => Unable to create a RebarShape based on the given curves
Rebar.CreateFromCurves(RevitDoc, RebarStyle.Standard, bartype, null,
null, ele, nml, curves2, RebarHookOrientation.Left,
RebarHookOrientation.Left, false, true);


第一个Rebar和第二个Rebar创建的过程几乎一模一样,除了坐标有点不同,为何一个可以另外一个却抛异常呢?

百思不得其解。

请教了我的同事Grzegorz,他指出创建函数的算法比较复杂,对于指定曲线的角度要求严格,小数点后面7位、8位的稍许区别都可能会导致异常抛出。最好的解决办法就是保持小数点后面最多6位的精度。据此我稍微修改了以下代码,就可以工作了。

curve = Line.CreateBound(
XYZ(6.22700217574493, 43.5110702844365, -10.0065608637852),
XYZ(6.22700217219427, 43.5110702591722, 7.70997373826235));
curves2.Add(curve);
curve = Line.CreateBound(
XYZ(6.22700217219427, 43.5110702591722, 7.70997373826235),
XYZ(6.22700217219427, 45.1676114744251, 7.70997373826235));
curves2.Add(curve);
curve = Line.CreateBound(
XYZ(6.22700217219427, 45.1676114744251, 7.70997373826235),
XYZ(6.22700217574493, 45.1676114996894, -10.0065608637852));
curves2.Add(curve);

....

private XYZ XYZ(double x, double y, double z)
{
return new XYZ(
Math.Round(x, 6), Math.Round(y, 6), Math.Round(z, 6));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐