2020年5月10日,西安,晴。
最近几天在研究如何创建钢筋,本来想的是在板上创建钢筋,奈何没有难度。后来在网上看见一个基坑喷锚网筋的模型,确实这个要是使用手动建模是非常费劲的,由于平时接触基坑的项目也不多,正好借此研究一下如何在倾斜的构件里创建钢筋,以备不时之需。当然以下这套方法同样适用于板钢筋的创建。
创建钢筋的API Revit给提供了以下三种,两类创建方法,第一类是根据曲线创建,第二类是根据几何形状创建。
我主要使用了第一类的方法根据曲线创建,来具体看下内容:
第一个doc 就不用说了; 第二个 选择钢筋类型, 对于箍筋需要设置为:RebarStyle.StirupTie. 如果对于直线钢筋或纵筋设置为RebarStyle.Standard。这里我们的网筋是直线钢筋所以设置为RebarStyle.Standard。 第三个 钢筋形状的类型,案例里我选的是项目里的钢筋。 第四、五个是弯钩的类型,案例里的是直线钢筋,这里都设置成null就行了。 第六个是所要创建钢筋的主体,主体不合适钢筋就会创建在主体外。 这里还有两个Revit的知识点,要在在主体上创建钢筋必须满足以下两个因素:①常规模型的材质必须为钢筋混凝土
②族参数必须选择可将钢筋附着到主体
第七个是钢筋所在的面向量。 第八个是绘制钢筋的曲线列表(注意:钢筋必须是首尾相连的)。 第九、十个是设置弯钩方向的,因为没有弯钩也就随意选了。 最后两个一个是使用存在的钢筋形状,另一个是创建一个新的钢筋形状。
(此图片和解题过程毫无关系) 得出来了一个公式: k = -(((x2 - x1) * (x1 - x0) + (y2 - y1) * (y1 - y0) + (z2 - z1) * (z1 - z0)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1))); xn = k * (x2 - x1) + x1; yn = k * (y2 - y1) + y1; zn = k * (z2 - z1) + z1;
终究没有错付数学老师的教导啊
接下来我们上代码,看看如何实现功能的吧
Selection sel = uiDoc.Selection;
Reference refFace = sel.PickObject(ObjectType.Face, "请选择一个面");
Element el = doc.GetElement(refFace.ElementId);//获得这个面所在的主体
PlanarFace pface = el.GetGeometryObjectFromReference(refFace) as PlanarFace;//获得面
EdgeArrayArray edgeArray = pface.EdgeLoops;//获得面的边线
HashSet<Curve> linelist1 = new HashSet<Curve>();//获得边线
foreach (EdgeArray edd in edgeArray)
{
foreach (Edge ed in edd)
{
Curve line = ed.AsCurve();
linelist1.Add(line);//获得面的边线
}
}
Curve curve1 = linelist1.ElementAt(0);//第一根线
Curve curve2 = null;//第一根线交线
Curve curve11 = null;//第一根线平行线
Curve curve22 = null;//第二根线平行线
foreach (Curve cu in linelist1)
{
try
{
if (curve1.Intersect(cu) == SetComparisonResult.Overlap)//第一条线有交点的线
{
curve2 = cu;
}
else if (curve1.Intersect(cu) == SetComparisonResult.Disjoint)//第一条线的平行线
{
curve11 = cu;
}
}
catch
{
}
}
foreach (Curve cuu in linelist1)
{
try
{
if (curve2.Intersect(cuu) == SetComparisonResult.Disjoint)//第二条线的平行线
{
curve22 = cuu;
}
}
catch
{
}
}
// 第一条线向平行线做垂线的垂点
XYZ NewXYZ = PointOfPointToLine(curve11.Evaluate(0.5, true), curve1.GetEndPoint(0), curve1.GetEndPoint(1));
//第二条线向平行线做垂点
XYZ NewXYZ2 = PointOfPointToLine(curve22.Evaluate(0.5, true), curve2.GetEndPoint(0), curve2.GetEndPoint(1));
double s = -50 / 304.8;//钢筋偏移距离即保护层厚度
double s2 = 0;//钢筋间距起始点
double s4 = 0;//钢筋间距起始点
double sy2 = 0;//钢筋间距起始点
double sy4 = 0;//钢筋间距起始点
double s3 = 300 / 304.8;//横向钢筋间距
double sy3 = 300 / 304.8;//纵向钢筋间距
XYZ normal = pface.FaceNormal;//面的向量
XYZ xYZ = XYZ.BasisZ;//偏移方向的平面法线
XYZ xYZ2 = XYZ.BasisX;//纵向钢筋偏移方向
Line line11 = Line.CreateBound(NewXYZ, curve11.Evaluate(0.5, true));//钢筋直线连接中点与垂足
Line line1 = line11.CreateOffset(s, xYZ) as Line;//钢筋偏移
Line line22 = Line.CreateBound(NewXYZ2, curve22.Evaluate(0.5, true));//纵向钢筋
Line line222 = line22.CreateOffset(s, xYZ2) as Line;//钢筋偏移
IList<Curve> curves = new List<Curve>();
curves.Add(line1);
RebarBarType barType = new FilteredElementCollector(doc).OfClass(typeof(RebarBarType)).FirstOrDefault(t => t.Name == "结构钢筋 1") as RebarBarType;
//横向钢筋
Rebar rebar = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
View3D view3D = doc.ActiveView as View3D;
rebar.SetSolidInView(view3D, true);
//纵向钢筋
IList<Curve> curvesy = new List<Curve>();
curvesy.Add(line222);
Rebar rebary = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curvesy, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
rebary.SetSolidInView(view3D, true);
double length = curve1.Length;
double gs = length / 2 / s3;//上下各偏移的根数
double lengthy = curve2.Length;//纵向长度
double gsy = lengthy / 2 / s3;//上下各偏移的根数
for (int i = 0; i < gs - 1; i++)
{
s2 = s2 + s3;
s4 = s4 - s3;
Line line2 = line1.CreateOffset(s2, normal) as Line;
Line line3 = line1.CreateOffset(s4, normal) as Line;
IList<Curve> curves2 = new List<Curve>();
curves2.Add(line2);
Rebar rebar2 = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curves2, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
rebar2.SetSolidInView(view3D, true);
IList<Curve> curves3 = new List<Curve>();
curves3.Add(line3);
Rebar rebar3 = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curves3, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
rebar3.SetSolidInView(view3D, true);
}
for (int j = 0; j < gsy - 1; j++)
{
sy2 = sy2 + sy3;
sy4 = sy4 - sy3;
Line liney1 = line222.CreateOffset(sy2, normal) as Line;
Line liney2 = line222.CreateOffset(sy4, normal) as Line;
IList<Curve> curvesy2 = new List<Curve>();
curvesy2.Add(liney1);
Rebar rebary2 = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curvesy2, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
rebary2.SetSolidInView(view3D, true);
IList<Curve> curvesy3 = new List<Curve>();
curvesy3.Add(liney2);
Rebar rebary3 = Rebar.CreateFromCurves(doc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, null, null,
el, normal, curvesy3, RebarHookOrientation.Right, RebarHookOrientation.Left, true, false);
rebary3.SetSolidInView(view3D, true);
}
整个案例的思路:
1.选择一个要创建钢筋的面,利用这个面找到主体。
2.获得面的边线,找到边线对应的位置即邻边与对边的关系。
3.创建钢筋线。
4.设置保护层厚度,即让钢筋线进行偏移。
Line line1 = line11.CreateOffset(s, xYZ) as Line;
5.创建钢筋网,通过复制钢筋线来实现。当然API也提供了钢筋集的创建方法即:固定数量、最大最小间距、间距数量的方法,但不太灵活,因此帅编此处弃用了这种方法。
使用固定数量API方法为
rebar.SetLayoutAsFixedNumber
每个参数的意思分别为:根数、间距、法线方向一致与否、第一栏钢筋显示与否、最后一栏钢筋显示与否。
if (null != rebar)
{
//固定数量创建钢筋集
rebar.SetLayoutAsFixedNumber(2, 6, false, true, true);
}
6.将钢筋在当前的三维中显示为实体。
rebar3.SetSolidInView(view3D, true);
这样就基本实现了这个功能
整体效果(可以在任何面上布置)
细部效果