Building Coder(Revit 二次开发)- 在两条线之间创建尺寸

原文链接: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();
  }

New dimension

另外你还可以在我的博文 iterating over the wall faces FindReferencesByDirection to shoot a ray 中找到获取 Reference 的代码。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值