Building Coder(Revit 二次开发)- 在两条线之间创建尺寸
2012-10-20 15:48
676 查看
原文链接:Create Dimension between Two Lines
如何创建尺寸是一个经常被问及的问题。我最近花了点儿时间研究并找到了一个解决方案,顺带纠正了 RevitLookup 中一个相关的错误。
问题
我尝试用编程的方式创建详细的图纸,特别是使用 ItemFactoryBase.NewDimension() 方法。我根据墙元素的几何特征在草图视图中绘制细节线(Detail Line),然后想插入相关的尺寸。但问题是我如何获取用于 NewDimension() 方法的属于细节线(Reference)的引用对象呢?
Jeremy
我建议在遇到 Revit 二次开发的问题时,首先研究如下的资料:
The Revit API 帮助文档(RevitAPI.chm)
The Revit API 开发指南(2013开始没有PDF版本了,只能在 Autodesk WikiHelp 浏览)
译者注:个人认为 2012 版的也够用了。Revit API 从 2011 到 2012 有了较大改变,但是 2012 到 2013 改动不大。
The Revit SDK 例程
其实我也是这么做的。结果发现 RevitLookup 中就有相关的实现:
你可以通过 Add-Ins > Revit Lookup > Test Framework... > Object Hierarchy > APIObject > Element > Dimension 来调用 DimensionHardWired 外部命令。它实现了上面这段代码。不过这里 RevitLookup 有个小 BUG:没有为以上这段代码添加事务。所以你需要在上面这段代码外围添加如下代码才能正确运行:
另外你还可以在我的博文 iterating
over the wall faces 和
FindReferencesByDirection to shoot a ray 中找到获取 Reference 的代码。
如何创建尺寸是一个经常被问及的问题。我最近花了点儿时间研究并找到了一个解决方案,顺带纠正了 RevitLookup 中一个相关的错误。
问题
我尝试用编程的方式创建详细的图纸,特别是使用 ItemFactoryBase.NewDimension() 方法。我根据墙元素的几何特征在草图视图中绘制细节线(Detail Line),然后想插入相关的尺寸。但问题是我如何获取用于 NewDimension() 方法的属于细节线(Reference)的引用对象呢?
Jeremy
我建议在遇到 Revit 二次开发的问题时,首先研究如下的资料:
The Revit API 帮助文档(RevitAPI.chm)
The Revit API 开发指南(2013开始没有PDF版本了,只能在 Autodesk WikiHelp 浏览)
译者注:个人认为 2012 版的也够用了。Revit API 从 2011 到 2012 有了较大改变,但是 2012 到 2013 改动不大。
The Revit SDK 例程
其实我也是这么做的。结果发现 RevitLookup 中就有相关的实现:
XYZ location1 = GeomUtils.kOrigin; XYZ location2 = new XYZ( 20.0, 0.0, 0.0 ); XYZ location3 = new XYZ( 0.0, 20.0, 0.0 ); XYZ location4 = new XYZ( 20.0, 20.0, 0.0 ); Curve curve1 = m_revitApp.Application.Create.NewLine( location1, location2, true ); Curve curve2 = m_revitApp.Application.Create.NewLine( location3, location4, true ); DetailCurve dCurve1 = null; DetailCurve dCurve2 = null; if( !doc.IsFamilyDocument ) { dCurve1 = doc.Create.NewDetailCurve( doc.ActiveView, curve1 ); dCurve2 = doc.Create.NewDetailCurve( doc.ActiveView, curve2 ); } else { // 只有基于细节(Detail)的族文档才能创建细节曲线(Detail Curve) if( null != doc.OwnerFamily && null != doc.OwnerFamily.FamilyCategory ) { if( !doc.OwnerFamily.FamilyCategory.Name.Contains( "Detail" ) ) { MessageBox.Show( "Please make sure you open a detail based family template.", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } } dCurve1 = doc.FamilyCreate.NewDetailCurve( doc.ActiveView, curve1 ); dCurve2 = doc.FamilyCreate.NewDetailCurve( doc.ActiveView, curve2 ); } Line line = m_revitApp.Application.Create.NewLine( location2, location4, true ); ReferenceArray refArray = new ReferenceArray(); refArray.Append( dCurve1.GeometryCurve.Reference ); refArray.Append( dCurve2.GeometryCurve.Reference ); if( !doc.IsFamilyDocument ) { doc.Create.NewDimension( doc.ActiveView, line, refArray ); } else { doc.FamilyCreate.NewDimension( doc.ActiveView, line, refArray ); }
你可以通过 Add-Ins > Revit Lookup > Test Framework... > Object Hierarchy > APIObject > Element > Dimension 来调用 DimensionHardWired 外部命令。它实现了上面这段代码。不过这里 RevitLookup 有个小 BUG:没有为以上这段代码添加事务。所以你需要在上面这段代码外围添加如下代码才能正确运行:
using( Transaction tx = new Transaction( doc ) ) { tx.Start( "DimensionHardWired" ); ...... tx.Commit(); }
另外你还可以在我的博文 iterating
over the wall faces 和
FindReferencesByDirection to shoot a ray 中找到获取 Reference 的代码。
相关文章推荐
- Building Coder(Revit 二次开发) - 在一个倾斜的面上创建墙
- Building Coder(Revit 二次开发) - 使用 FindReferencesByDirection 创建墙体之间的尺寸标注
- Revit 二次开发之“在两个机械设备之间创建风管”
- Building Coder(Revit 二次开发) - 改变元素类型
- Building Coder(Revit 二次开发) - 设置标签类型
- Building Coder(Revit 二次开发) - 拖放API
- Building Coder(Revit 二次开发) - NewFamilyInstance() 重载版本的选择
- Building Coder(Revit 二次开发) - RevitLoopup 更新
- Building Coder(Revit 二次开发) - 列出链接文件和 TransmissionData
- Building Coder(Revit 二次开发) - 改变剖视图的视图类型并且隐藏切割线
- Building Coder(Revit 二次开发)- 关于楼板边界的重新思考
- Building Coder(Revit 二次开发) - 针对视图和阶段进行过滤
- Building Coder(Revit 二次开发) - 可扩展存储
- Building Coder(Revit 二次开发) - 失败回滚(Failure Rollback)
- Building Coder(Revit 二次开发) - 为一个共享参数绑定添加一个类别
- Building Coder(Revit 二次开发) - 元素层级事件(上)
- Building Coder(Revit 二次开发) - 组合使用 Revit 和 Vault
- Building Coder(Revit 二次开发) - 分解DWG文件
- Building Coder(Revit 二次开发) - 参数访问和计划信息
- Building Coder(Revit 二次开发) - 失败处理API(上)