通过 API 去创建一个结构桁架,涉及创建约束和标注等。
博客内容涉及的代码来自 SDK CreateTruss。
运行命令,创建桁架。桁架有六条杆。一条上弦杆,一条下弦杆,四条腹杆(绿色和黑色)。同时,还有不可见的约束。下弦杆和底参照平面的约束,上弦杆和左、底、右、上参照平面的约束,黑色腹杆和右参照平面的约束。另外还有两个角度标注,它们也是约束。
步骤:
// 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);
}
步骤:
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);
}
步骤:
// 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());
}
左边绿色腹杆:
// 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;
右边绿色腹杆:
// 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);