如何编程在Revit里创建长度小于0.8mm的线

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

时间: 2024-08-02 03:18:17

如何编程在Revit里创建长度小于0.8mm的线的相关文章

51Nod - 1107 斜率小于0的连线数量

二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4,6),其中(1,5)同(2,3)(3,4)的连线斜率 < 0,因此斜率小于0的连线数量为2. Input第1行:1个数N,N为点的数量(0 <= N <= 50000) 第2 - N + 1行:N个点的坐标,坐标为整数.(0 <= Xii , Yii <= 10^9)Output

51NOD——N 1107 斜率小于0的连线数量

https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4,6),其中(1,5)同(2,3)(3,4)的连线斜率 < 0,因

51nod 1107 1107 斜率小于0的连线数量

基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4,6),其中(1,5)同(2,3)(3,4)的连线斜率 < 0,因此斜率小于0的连线数量为2. Input 第1行:1个数N,N为点的数量(0 <= N <= 50000) 第2 - N + 1行:N个点的坐标

51 Nod 1107 斜率小于0的连线数量 (转换为归并求逆序数或者直接树状数组,超级详细题解!!!)

1107 斜率小于0的连线数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4,6),其中(1,5)同(2,3)(3,4)的连线斜率 < 0,因此斜率小于0的连线数量为2. Input 第1行:1个数N,N为点的数量(0 <= N <= 50000) 第2

Java并发编程:线程的创建

.title { text-align: center } .todo { font-family: monospace; color: red } .done { color: green } .tag { background-color: #eee; font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal } .timestamp { color: #bebebe } .timestamp-kwd

揭开SAP Fiori编程模型规范里注解的神秘面纱 - @OData.publish

今天是2020年2月1日鼠年大年初八,这是Jerry鼠年的第8篇文章,也是汪子熙公众号总共第207篇原创文章. Jerry的前一篇文章 揭开SAP Fiori编程模型规范里注解的神秘面纱 - @ObjectModel.readOnly工作原理解析,给大家分享了@ObjectModel.readOnly这个注解对应的Fiori UI和ABAP后台的工作原理. 今天我们继续研究另一个注解@OData.publish. 在SAP官网的ABAP Programming Model for SAP Fio

C#在outlook里创建一封邮件到草稿箱

原文:C#在outlook里创建一封邮件到草稿箱 1.引用Microsoft.Office.Interop.Outlook.dll 2.  实现代码 1 public static int SendToDraft(List<string> to, List<string> cc, List<string> bcc, string subject, string content, List<string> attachments, ref string err

MySQL里创建外键时错误的解决

--MySQL里创建外键时错误的解决--------------------------------2014/04/30在MySQL里创建外键时(Alter table xxx add constraint fk_xxx foreign key),提示错误,但只提示很简单的信息:ERROR 1005 (HY000): Can't create table '.\env_mon\#sql-698_6.frm' (errno: 150).根本起不到解决问题的作用.要看错误的详细提示,可以使用命令:(

ASP.NET MVC项目里创建一个aspx视图

先从控制器里添加视图 视图引擎选"ASPX(C#)",使用布局或模板页不要选. 在Views\EAV目录里,生成的aspx是个单独的页面,没有代码文件,所以代码也要写在这个文件里. @ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" @ Import Namespace="System" @ Import Namespace="