您的位置:首页 > 产品设计 > UI/UE

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 中就有相关的实现:

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 的代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: