如何编程在Revit里创建长度小于0.8mm的线
来源:互联网 发布:淘宝抽纸 编辑:程序博客网 时间:2024/06/06 08:46
Revit不知为何出有一个奇怪的规矩,那就是无法绘制长度小于 0.8mm的长度的线. (0.8mm等于 32分之一英寸). 导致很多小的短线无法绘制.
在轻钢薄壁构件里,其厚度有的只有0.5, 有的是0.7, 均无法绘制. 这给Revit的工作带来一些局限性.
这里有一个用编程的办法来绕弯路创建小于0.8mm, 其用法确实有点难以想到.
首先我们创建一个长度放大100倍的长线. 然后给这个线添加尺寸约束,并绑定到一个参数上. 最后指定参数的值为实际长度. 最后删除标准和临时参数. 这样就可以绘制出来长度小于0.8mm的线.
下面是代码演示. 大家可以自己看下.
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]class RvtTestCommand : IExternalCommand{ // member variables for top level access to the Revit database // public Application _app; public Document m_doc; string BareFamilyName = "type1"; // command main // public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { _app = commandData.Application.Application; m_doc = commandData.Application.ActiveUIDocument.Document; UIApplication m_revit = commandData.Application; Transaction trans = new Transaction(m_doc); trans.Start("crateshortline"); DrawLine(_app.Create, m_doc, m_doc.ActiveView, true, new XYZ(0.00087971 / 304.8, 4.85813270 / 304.8, 0), new XYZ(0.34120938 / 304.8, 4.18071790 / 304.8, 0)); trans.Commit(); return Result.Succeeded; } public XYZ GetEndPoint(Curve c, int index) { return c.GetEndPoint(index); } public Reference GetEndPointReference(Curve c, int index) { return c.get_EndPointReference(index); } public double MmToFeet(double mm) { return mm / 304.8; } public void DrawLine(Autodesk.Revit.Creation.Application appCreate, Document famDoc, View workView,bool bOnXYPlane, XYZ startPoint, XYZ endPoint) { XYZ _offset = new XYZ(0, 0, 0); double dLength = startPoint.DistanceTo(endPoint); if (dLength < 1/32.0/12.0) { if (dLength == 0) { return; } else if ((dLength * 100) < 1 / 32.0 / 12.0) { TaskDialog.Show("lengh check","Line too small to draw, even when multiplied by 100"); } else { try { XYZ ptVector = endPoint - startPoint; XYZ ptMultiplied = startPoint + ptVector * 100; Line revitLine = appCreate.NewLineBound(ptMultiplied + _offset, startPoint + _offset); DetailLine detailLine2 = famDoc.FamilyCreate.NewDetailCurve(workView, revitLine) as DetailLine; XYZ ptTempLine = startPoint + new XYZ(MmToFeet(2.0), MmToFeet(1.855), 0); Line revitLineTemp = appCreate.NewLineBound( ptTempLine + _offset, startPoint + _offset); DetailLine detailLineTemp = famDoc.FamilyCreate.NewDetailCurve(workView, revitLineTemp) as DetailLine; famDoc.Regenerate(); try { // dimension of whole length ReferenceArray refArray = new ReferenceArray(); refArray.Append(GetEndPointReference(detailLine2.GeometryCurve, 0)); refArray.Append(GetEndPointReference(detailLine2.GeometryCurve, 1)); XYZ p1 = new XYZ( GetEndPoint(revitLine, 0).X + 0.1, GetEndPoint(revitLine, 0).Y + 0.1, GetEndPoint(revitLine, 0).Z); XYZ p2 = new XYZ( GetEndPoint(revitLine, 1).X + 0.1, GetEndPoint(revitLine, 1).Y + 0.1, GetEndPoint(revitLine, 1).Z); Line line = appCreate.NewLineBound(p1, p2); Dimension dimensionTotal = famDoc.FamilyCreate.NewLinearDimension(workView, line, refArray); FamilyParameter famParamL1 = famDoc.FamilyManager.get_Parameter("smalllinelength"); try { if (famParamL1 == null) { famParamL1 = famDoc.FamilyManager.AddParameter("smalllinelength", BuiltInParameterGroup.PG_GENERAL, ParameterType.Length, true); } if (famDoc.FamilyManager.Types.Size == 0) { famDoc.FamilyManager.NewType(this.BareFamilyName); } famDoc.FamilyManager.Set(famParamL1, dLength); dimensionTotal.FamilyLabel = famParamL1; famDoc.FamilyManager.Set(famParamL1, dLength); // needed to make it resize properly } finally { famDoc.Delete(dimensionTotal.Id); // now remove the dimension, no longer needed famDoc.FamilyManager.RemoveParameter(famParamL1); // now remove the parameter, no longer needed } } finally { famDoc.Delete(detailLineTemp.Id); } } catch (System.Exception exception) { TaskDialog.Show("exception", exception.Message); } } } else { try { Line revitLine = appCreate.NewLineBound(startPoint + _offset, endPoint + _offset); DetailLine detailLine2 = famDoc.FamilyCreate.NewDetailCurve(workView, revitLine) as DetailLine; } catch (System.Exception exception) { TaskDialog.Show("exception",exception.Message); } } }}
作者:叶雄进 Autodesk特聘开发咨询专家,橄榄山软件首席研发
转载请注明原文出处。http://blog.csdn.net/joexiongjin/article/details/42003917
1 0
- 如何编程在Revit里创建长度小于0.8mm的线
- 在Revit 2013里 如何编程创建(东西南北四个方向)的立面图
- 如何编程创建Revit里面的视图过滤器对象
- 在Revit中,如何编程创建新类型(如窗户或墙)
- 如何在64位操作系统里让Revit的命令连接Access数据库?
- 编程如何获得通过草图创建的Revit构件关联的原始草图对象
- 编程如何实现使用新建的Revit楼板族,创建楼板构件
- IE6下定义height高度异常,如何在IE6里定义高度小于18px的盒子
- 长度小于3的正整数
- Revit启动后,如何把你的命令显示在Revit的Ribbon(工具栏)上?
- Revit编程如何获取内置参数对应的中文字符串?
- 如何编程访问和修改Revit项目的单位信息
- 如何在edius里创建4K的工程预设
- 如何在xcode里创建自己的代码片段库
- 如何在你的控制台程序里创建消息循环
- Revit二次开发_在Revit启动后创建Tab
- 如何在visual2010 里创建默认注释
- 如何在win7里创建.exe可执行文件
- max/min函数的用法
- 百度度地图总是提示key 验证出错! 请在 AndroidManifest.xml 文件中检查 key 设置解决办法
- 再探java基础——throw与throws
- Largest Rectangle in Histogram 直方图的最大正方形
- LeetCode(39) Combination Sum
- 如何编程在Revit里创建长度小于0.8mm的线
- Android Studio 1.0 导入第三方类库的方法
- codeforces 496C Removing Columns 贪心
- android view图层获取焦点
- 黑马程序员—IOS环境搭建与开发入门注册APPLE ID(一)
- Windows下安装FFTW
- raccheck
- python连续处理两行数据
- 三极管的工作原理