209 lines
7.9 KiB
C#
209 lines
7.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
using Bentley.DgnPlatformNET;
|
|||
|
|
using Bentley.DgnPlatformNET.Elements;
|
|||
|
|
using Bentley.GeometryNET;
|
|||
|
|
using Bentley.MstnPlatformNET;
|
|||
|
|
|
|||
|
|
namespace RebarMsAddins
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋帮助类
|
|||
|
|
/// </summary>
|
|||
|
|
internal static class RebarHelpers
|
|||
|
|
{
|
|||
|
|
public static void CreateRebarSolid(List<Rebar> rebars, string levelName = null)
|
|||
|
|
{
|
|||
|
|
var dgnModel = Session.Instance.GetActiveDgnModel();
|
|||
|
|
|
|||
|
|
if (rebars == null || rebars.Count == 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
double uorMeter = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter;//米与分辨率单位的比值,绝对长度,不随主、子单位设置而改变
|
|||
|
|
var modelRef = Session.Instance.GetActiveDgnModelRef();
|
|||
|
|
var model = Session.Instance.GetActiveDgnModel();
|
|||
|
|
var layer = model.GetLevelCache().GetLevelByName("JG_EC_ZXJ");
|
|||
|
|
|
|||
|
|
foreach (var rebar in rebars)
|
|||
|
|
{
|
|||
|
|
var host = new CustomItemHost(rebar.Element, false);
|
|||
|
|
CurveVector pathCurve = null;
|
|||
|
|
CurveVector profile = null;
|
|||
|
|
var d = rebar.Diameter / 1000 * uorMeter;
|
|||
|
|
//"纵向筋"需要自己定义轮廓和放样线
|
|||
|
|
if (rebar.Element.LevelId == layer.LevelId)
|
|||
|
|
{
|
|||
|
|
var arcs = rebar.Element.GetArcs();
|
|||
|
|
if (arcs.Count > 0)
|
|||
|
|
{
|
|||
|
|
//获取圆弧
|
|||
|
|
var arc = arcs.FirstOrDefault();
|
|||
|
|
//得到圆弧平面的法向
|
|||
|
|
if (!arc.Vector0.CrossProduct(arc.Vector90).TryNormalize(out var normal))
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var vector = normal * (rebar.Length / 1000 * uorMeter) * 0.5;
|
|||
|
|
//拿到以元素平面为中心的两侧点,作为放样线起终点
|
|||
|
|
var startPoint = arc.Center - vector;
|
|||
|
|
var endPoint = arc.Center + vector;
|
|||
|
|
//创建路径
|
|||
|
|
List<DPoint3d> pos = new List<DPoint3d>() { startPoint, endPoint };
|
|||
|
|
//ElementCreationHelpers.CreateLine(startPoint, endPoint);
|
|||
|
|
pathCurve = CurveVector.CreateLinear(pos, CurveVector.BoundaryType.Open, false);
|
|||
|
|
//截面
|
|||
|
|
DEllipse3d dEllipse3D = DEllipse3d.FromCenterRadiusNormal(startPoint, d / 2, normal);
|
|||
|
|
profile = CurveVector.CreateDisk(dEllipse3D, CurveVector.BoundaryType.Outer);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
pathCurve = rebar.Element.GetCurveVector();
|
|||
|
|
//起点和起点的切向
|
|||
|
|
pathCurve.GetStartEnd(out var p1, out _, out var t1, out _);
|
|||
|
|
//在起点创建截面
|
|||
|
|
DEllipse3d ellipse = DEllipse3d.FromCenterRadiusNormal(p1, d / 2, t1);
|
|||
|
|
EllipseElement ellipseElem = new EllipseElement(dgnModel, null, ellipse);//使用椭圆几何创建椭圆元素
|
|||
|
|
profile = ellipseElem.GetCurveVector();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (profile == null || pathCurve == null)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
Create.BodyFromSweep(
|
|||
|
|
out var entity,
|
|||
|
|
profile,
|
|||
|
|
pathCurve,
|
|||
|
|
modelRef,
|
|||
|
|
false,
|
|||
|
|
true,
|
|||
|
|
false,
|
|||
|
|
null,
|
|||
|
|
null,
|
|||
|
|
null,
|
|||
|
|
null);
|
|||
|
|
|
|||
|
|
if (entity != null)
|
|||
|
|
{
|
|||
|
|
BentleyStatus result = Convert1.BodyToElement(out Element eeh, entity, null, dgnModel);//将SolidKernelEntity转换为元素
|
|||
|
|
eeh.AddToModel();//将元素写入模型
|
|||
|
|
if (!string.IsNullOrEmpty(levelName))
|
|||
|
|
{
|
|||
|
|
eeh.SetLevel(levelName);
|
|||
|
|
}
|
|||
|
|
rebar.Element.DeliverItemTypesTo(eeh);
|
|||
|
|
//eeh.AttachItemType()
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按图层获取钢筋的数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="levelName"></param>
|
|||
|
|
/// <returns>钢筋的数据集合</returns>
|
|||
|
|
public static List<Rebar> GetRebarDataByLevelName(string levelName)
|
|||
|
|
{
|
|||
|
|
//获取当前激活的模型
|
|||
|
|
DgnModel model = Session.Instance.GetActiveDgnModel();
|
|||
|
|
//获取图层
|
|||
|
|
var layer = model.GetLevelCache().GetLevelByName(levelName);
|
|||
|
|
//拿到图层上的元素
|
|||
|
|
var elems = model.GetGraphicElements().Where(e => e.LevelId == layer.LevelId).ToList();
|
|||
|
|
List<Rebar> rebars = new List<Rebar>();
|
|||
|
|
foreach (var elem in elems)
|
|||
|
|
{
|
|||
|
|
//整理钢筋数据
|
|||
|
|
Rebar rebar = new Rebar()
|
|||
|
|
{
|
|||
|
|
Function = elem.GetRebarPropertyValue("ID-100-名称")?.ToString(),
|
|||
|
|
Number = elem.GetRebarPropertyValue("ID-100-编号")?.ToString(),
|
|||
|
|
StrengthRating = elem.GetRebarPropertyValue("TC-100-钢筋强度等级")?.ToString(),
|
|||
|
|
Diameter = Convert.ToDouble(elem.GetRebarPropertyValue("TC-100-直径")),
|
|||
|
|
Element = elem,
|
|||
|
|
Length = elem.GetLength()
|
|||
|
|
};
|
|||
|
|
//纵向筋通过读属性获取
|
|||
|
|
if (levelName == "JG_EC_ZXJ")
|
|||
|
|
{
|
|||
|
|
rebar.Length = Convert.ToDouble(elem.GetRebarPropertyValue("TC-100-长度"));
|
|||
|
|
}
|
|||
|
|
rebars.Add(rebar);
|
|||
|
|
}
|
|||
|
|
return rebars;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 如何使用
|
|||
|
|
/// </summary>
|
|||
|
|
internal static class Using
|
|||
|
|
{
|
|||
|
|
public static void Command(string unparsed)
|
|||
|
|
{
|
|||
|
|
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
|
|||
|
|
var dgnModelRef = Session.Instance.GetActiveDgnModelRef();
|
|||
|
|
|
|||
|
|
//二衬结构附加筋
|
|||
|
|
var fjj = RebarHelpers.GetRebarDataByLevelName("JG_EC_FJJ");
|
|||
|
|
//二衬结构箍筋
|
|||
|
|
var guj = RebarHelpers.GetRebarDataByLevelName("JG_EC_GuJ");
|
|||
|
|
//二衬结构拉筋
|
|||
|
|
var laj = RebarHelpers.GetRebarDataByLevelName("JG_EC_LaJ");
|
|||
|
|
//二衬结构主筋
|
|||
|
|
var zj = RebarHelpers.GetRebarDataByLevelName("JG_EC_ZJ");
|
|||
|
|
//二衬结构纵向筋
|
|||
|
|
var zxj = RebarHelpers.GetRebarDataByLevelName("JG_EC_ZXJ");
|
|||
|
|
List<Rebar> list = new List<Rebar>();
|
|||
|
|
|
|||
|
|
RebarHelpers.CreateRebarSolid(fjj, "JG_EC_GJMX");
|
|||
|
|
RebarHelpers.CreateRebarSolid(guj, "JG_EC_GJMX");
|
|||
|
|
RebarHelpers.CreateRebarSolid(laj, "JG_EC_GJMX");
|
|||
|
|
RebarHelpers.CreateRebarSolid(zxj, "JG_EC_GJMX");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋
|
|||
|
|
/// </summary>
|
|||
|
|
internal class Rebar
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public override string ToString() { return $"功能:{Function},编号:{Number},直径:{Diameter},长度:{Length}"; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋直径,mm
|
|||
|
|
/// </summary>
|
|||
|
|
public double Diameter { get; set; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 关联的元素
|
|||
|
|
/// </summary>
|
|||
|
|
public Element Element { get; set; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋类型 拉筋,箍筋,主筋,纵向筋、附加筋等
|
|||
|
|
/// </summary>
|
|||
|
|
public string Function { get; set; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋长度
|
|||
|
|
/// </summary>
|
|||
|
|
public double Length { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编号N
|
|||
|
|
/// </summary>
|
|||
|
|
public string Number { get; set; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 钢筋强度等级HPB
|
|||
|
|
/// </summary>
|
|||
|
|
public string StrengthRating { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|