RevitAPI: Rebar.CreateFromCurves抛出异常: Unable to create a RebarShape based on the given curves
2014-12-17 10:27
471 查看
我们知道通过Rebar提供几个创建的函数,其中一个是CreateFromCurves,
我们主要看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.
第一个Rebar和第二个Rebar创建的过程几乎一模一样,除了坐标有点不同,为何一个可以另外一个却抛异常呢?
百思不得其解。
请教了我的同事Grzegorz,他指出创建函数的算法比较复杂,对于指定曲线的角度要求严格,小数点后面7位、8位的稍许区别都可能会导致异常抛出。最好的解决办法就是保持小数点后面最多6位的精度。据此我稍微修改了以下代码,就可以工作了。
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)); }
相关文章推荐
- Unable to Start Debugging on the Web Server 异常的处理方法
- Unable to create envelope from given source:
- oracle jdeveloper 11g 安装到quickstart选择启动 异常:Unable to create an instance of the Java Virtual Machine
- Unable to create any keyboard shortcuts after the iOS 6.1.3 update on iPad.
- Error “Unable to copy the file xxx from the project template to the project. Can't find the file \xxxx” when create VS template
- An application to fetch the release sources from Visual SouceSafe based on an Excel migration plan
- Unable to create the store directory. (Exception from HRESULT: 0x80131468)
- eclipse异常报错:Unable to build: the file dx.jar was not loaded from the SDK folder
- Hive 笔记异常(java.sql.SQLException: Unable to open a test connection to the given database. JDBC url =)
- Unable to create this part due to an internal errorReason for the failure An unexpected exception was thrown
- How to use the Install from Media feature to promote Windows Server 2003-based domain controllers
- [原]Unable to start debugging on the web server.Debugging failes because integrated Windows authentication is not enabled.
- Unable to start debugging on the web server. The project is not configured to be debugged.
- java 问题多多之Unable to create the selected preference page
- Unable to get the project ile from the web server错误的解决方法
- Unable to find a javac compiler;Perhaps JAVA_HOME does not point to the JDK异常产生原因和解决方法。
- Unable to start debugging on the Web Server
- Unable to start debugging on the web server
- Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK(转
- VS2005无法调试报错:Unable to start debugging on the Web server