Revit SDK 介绍:CreateTruss 创建结构桁架

前言

通过 API 去创建一个结构桁架,涉及创建约束和标注等。

内容

博客内容涉及的代码来自 SDK CreateTruss。
Revit SDK 介绍:CreateTruss 创建结构桁架_第1张图片
运行命令,创建桁架。桁架有六条杆。一条上弦杆,一条下弦杆,四条腹杆(绿色和黑色)。同时,还有不可见的约束。下弦杆和底参照平面的约束,上弦杆和左、底、右、上参照平面的约束,黑色腹杆和右参照平面的约束。另外还有两个角度标注,它们也是约束。

Revit SDK 介绍:CreateTruss 创建结构桁架_第2张图片
核心代码都在函数 MakeNewTruss() 中。

Revit SDK 介绍:CreateTruss 创建结构桁架_第3张图片

下弦杆

步骤:

  1. 得到参照平面 ‘左’ 和 ‘底’ 的交点,‘右’ 和 ‘底’ 的交点
  2. 用上面得到的点创建桁架的线,即下弦杆
  3. 创建下弦杆和参照平面 ‘底’ 的约束
// Create bottom chord along "bottom" from "left" to "right"
Autodesk.Revit.DB.XYZ bottomLeft = GetIntersection(bottomLine, leftLine);
Autodesk.Revit.DB.XYZ bottomRight = GetIntersection(bottomLine, rightLine);
ModelCurve bottomChord = MakeTrussCurve(bottomLeft, bottomRight, sPlane, TrussCurveType.BottomChord);
if (null != bottomChord)
{
     
   // Add the alignment constraint to the bottom chord.
   Curve geometryCurve = bottomChord.GeometryCurve;
   // Lock the bottom chord to bottom reference plan
   m_familyCreator.NewAlignment(level1, bottom.GetReference(), geometryCurve.Reference);
}

创建腹杆(黑色)

步骤:

  1. 得到参照平面 ‘右’ 和 ‘顶部’ 的交点
  2. 创建腹杆(黑色)
  3. 创建腹杆(黑色)和参照平面 ‘右’ 的约束
Autodesk.Revit.DB.XYZ topRight = GetIntersection(topLine, rightLine);
ModelCurve rightWeb = MakeTrussCurve(bottomRight, topRight, sPlane, TrussCurveType.Web);
if (null != rightWeb)
{
     
   // Add the alignment constraint to the right web chord.
   Curve geometryCurve = rightWeb.GeometryCurve;
   // Lock the right web chord to right reference plan
   m_familyCreator.NewAlignment(level1, right.GetReference(), geometryCurve.Reference);
}

上弦杆

步骤:

  1. 创建上弦杆
  2. 添加上弦杆与参照平面的约束(左下角与 ‘左’ 和 ‘底’ ,右上角与 ‘顶部’ 和 ‘右’)
// Create top chord diagonally from bottom-left to top-right
ModelCurve topChord = MakeTrussCurve(bottomLeft, topRight, sPlane, TrussCurveType.TopChord);
if (null != topChord)
{
     
   // Add the alignment constraint to the top chord.
   Curve geometryCurve = topChord.GeometryCurve;
   // Lock the start point of top chord to the Intersection of left and bottom reference plan
   m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(0), left.GetReference());
   m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(0), bottom.GetReference());
   // Lock the end point of top chord to the Intersection of right and top reference plan
   m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(1), top.GetReference());
   m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(1), right.GetReference());
}

腹杆(绿色)

左边绿色腹杆:

  1. 得到参照平面 ‘底’ 和 ‘中心’ 交点
  2. 设定腹杆角度,并创建腹杆
  3. 添加角度标注并且锁定
// Create angled web from midpoint to the narrow end of the truss
Autodesk.Revit.DB.XYZ bottomMidPoint = GetIntersection(bottomLine, centerLine);
Line webDirection = Line.CreateUnbound(bottomMidPoint, angleDirection);
Autodesk.Revit.DB.XYZ endOfWeb = GetIntersection(topChord.GeometryCurve as Line, webDirection);
ModelCurve angledWeb = MakeTrussCurve(bottomMidPoint, endOfWeb, sPlane, TrussCurveType.Web);

// Add a dimension to force the angle to be stable even when truss length and height are modified
Arc dimensionArc = Arc.Create(
             bottomMidPoint, angledWeb.GeometryCurve.Length / 2, webAngleRadians, Math.PI, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY);
Dimension createdDim = m_familyCreator.NewAngularDimension(
             level1, dimensionArc, angledWeb.GeometryCurve.Reference, bottomChord.GeometryCurve.Reference);
if (null != createdDim)
   createdDim.IsLocked = true;

右边绿色腹杆:

  1. 得到参照平面 ‘底’ 和 ‘右’ 交点
  2. 设定腹杆角度,并创建腹杆
  3. 添加角度标注并且锁定
// Create angled web from corner to top of truss
Autodesk.Revit.DB.XYZ bottomRight2 = GetIntersection(bottomLine, rightLine);
webDirection = Line.CreateUnbound(bottomRight2, angleDirection);
endOfWeb = GetIntersection(topChord.GeometryCurve as Line, webDirection);
ModelCurve angledWeb2 = MakeTrussCurve(bottomRight, endOfWeb, sPlane, TrussCurveType.Web);

// Add a dimension to force the angle to be stable even when truss length and height are modified
dimensionArc = Arc.Create(
             bottomRight, angledWeb2.GeometryCurve.Length / 2, webAngleRadians, Math.PI, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY);
createdDim = m_familyCreator.NewAngularDimension(
             level1, dimensionArc, angledWeb2.GeometryCurve.Reference, bottomChord.GeometryCurve.Reference);
if (null != createdDim)
   createdDim.IsLocked = true;

中间绿色腹杆:
连接底部中心点与绿色有腹杆,得中间绿色腹杆。

//Connect bottom midpoint to end of the angled web
ModelCurve braceWeb = MakeTrussCurve(bottomMidPoint, endOfWeb, sPlane, TrussCurveType.Web);

效果

导入模型文件中的效果:
Revit SDK 介绍:CreateTruss 创建结构桁架_第4张图片

你可能感兴趣的:(Revit,SDK,介绍)