如何编程在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
原创粉丝点击