MultiplanarRebar--Revit多平面钢筋
多平面钢筋——High
This sample is to demo multiplanar rebar creation in API. A user scenario of multiplanar rebar is corbel `s reinforcement. This sample is to reinforce sloped corbel(s).
通过API来创建多平面钢筋的小样。用户方案中会涉及到多平面钢筋的是斜牛腿的钢筋,这个例子就是给牛腿(可以多个)配置钢筋。
效果图:
1、如何判断一个面是不规则多边形
private static bool IsTrapezoid(
XYZ hostNormal, PlanarFace corbelBottomFace, Edge bottomEdge,
out PlanarFace trapezoidFace, out Edge topEdge,
out Edge leftEdge, out Edge rightEdge)
{
PlanarFace face1 = bottomEdge.GetFace(0) as PlanarFace;
PlanarFace face2 = bottomEdge.GetFace(1) as PlanarFace;
trapezoidFace = face1 == corbelBottomFace ? face2 : face1;
EdgeArray trapezoidFaceEdges = trapezoidFace.EdgeLoops.get_Item(0);
XYZ bottomEdgeDir = (bottomEdge.Evaluate(1.0) - bottomEdge.Evaluate(0.0)).Normalize();
int bottomEdgeIndex = -1;
topEdge = null;
for (int i = 0; i < trapezoidFaceEdges.Size; i++)
{
Edge edge = trapezoidFaceEdges.get_Item(i);
XYZ edgeDir = (edge.Evaluate(1.0) - edge.Evaluate(0.0)).Normalize();
if (edgeDir.IsAlmostEqualTo(bottomEdgeDir) ||
edgeDir.IsAlmostEqualTo(-bottomEdgeDir))
{
if (edge.Evaluate(0.0).IsAlmostEqualTo(bottomEdge.Evaluate(0.0)))
{
bottomEdge = edge;
bottomEdgeIndex = i;
}
else
{
topEdge = edge;
}
}
}
leftEdge = trapezoidFaceEdges.get_Item((trapezoidFaceEdges.Size + bottomEdgeIndex - 1) % trapezoidFaceEdges.Size);
rightEdge = trapezoidFaceEdges.get_Item((bottomEdgeIndex + 1) % trapezoidFaceEdges.Size);
XYZ leftEdgeDir = (leftEdge.Evaluate(1.0) - leftEdge.Evaluate(0.0)).Normalize();
bool isLeftEdgeVertical = false;
if (leftEdgeDir.IsAlmostEqualTo(hostNormal) ||
leftEdgeDir.IsAlmostEqualTo(-hostNormal))
{
isLeftEdgeVertical = true;
}
XYZ rightEdgeDir = (rightEdge.Evaluate(1.0) - rightEdge.Evaluate(0.0)).Normalize();
bool rightEdgeIsVertical = false;
if (rightEdgeDir.IsAlmostEqualTo(hostNormal) ||
rightEdgeDir.IsAlmostEqualTo(-hostNormal))
{
rightEdgeIsVertical = true;
}
return isLeftEdgeVertical && !rightEdgeIsVertical;
}
2、如何判断一边共边面
private static XYZ GetCommonVertex(Edge edge1, Edge edge2)
{
XYZ edge1V0 = edge1.Evaluate(0.0);
XYZ edge1V1 = edge1.Evaluate(1.0);
XYZ edge2V0 = edge2.Evaluate(0.0);
XYZ edge2V1 = edge2.Evaluate(1.0);
if (edge1V0.IsAlmostEqualTo(edge2V0) ||
edge1V0.IsAlmostEqualTo(edge2V1))
{
return edge1V0;
}
else if (edge1V1.IsAlmostEqualTo(edge2V0) ||
edge1V1.IsAlmostEqualTo(edge2V1))
{
return edge1V1;
}
return null;
}
3、两个面之间的间距
private static double GetDistance(PlanarFace face1, PlanarFace face2)
{
BoundingBoxUV boxUV = face2.GetBoundingBox();
// 中点位置
UV center = (boxUV.Max + boxUV.Min) * 0.5;
// 中点的坐标
XYZ centerPt = face2.Evaluate(center);
// face1面上中点的投影的点
IntersectionResult result = face1.Project(centerPt);
return face1.Project(centerPt).Distance;
}
4、创建一个多平面的钢筋形状
// 多平面的rebarshape
RebarShape barshape = profileCopy.ConstructMultiplanarRebarShape(options.RevitDoc,
0.5 * options.MultiplanarBarType.StirrupTieBendDiameter);
Rebar newRebar = Rebar.CreateFromRebarShape(
options.RevitDoc, barshape,
options.MultiplanarBarType,
m_corbel, origin, vecX, vecY);
public RebarShape ConstructMultiplanarRebarShape(Document revitDoc, double bendDiameter)
{
// Construct a segment definition with 2 lines.
RebarShapeDefinitionBySegments shapedef = new RebarShapeDefinitionBySegments(revitDoc, 2);
// Define parameters for the dimension.
...
ElementId MM = SharedParameterUtil.GetOrCreateDef("MM", revitDoc);
// Set parameters default values according to the size Trapezoid shape.
...
shapedef.AddParameter(MM, 15);
// Rebar shape geometry curves consist of Line S0 and Line S1.
//
//
// |Y V1
// |--S0(B)--\
// | \S1(H, K)
// | \
//---------|O-----------\----X
// |
// Define multi-planar definition
// 多平面
RebarShapeMultiplanarDefinition multiPlanarDef = new RebarShapeMultiplanarDefinition(bendDiameter);
multiPlanarDef.DepthParamId = MM;
// Realize the Rebar shape with creation static method.
// The RebarStype is stirrupTie, and it will attach to the top cover.
RebarShape newshape = RebarShape.Create(revitDoc, shapedef, multiPlanarDef,
RebarStyle.StirrupTie, StirrupTieAttachmentType.InteriorFace,
0, RebarHookOrientation.Left, 0, RebarHookOrientation.Left, 0);
// Make sure we can see the created shape from the browser.
IList<Curve> curvesForBrowser = newshape.GetCurvesForBrowser();
if (curvesForBrowser.Count == 0)
{
throw new Exception("The Rebar shape is invisible in browser.");
}
return newshape;
}
BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!
-
微信公众号: BIM树洞
-
知乎专栏:BIM树洞
-
气氛组博客:http://www.31bim.com
-
BIM应用及咨询,CAD,Revit, OpenGL,图形开发交流,加Q群1083064224