最近要进行管线留洞,核对施工图的留洞正确性,虽然很多插件都有这个功能,原理也很简单,无非就是创建一个洞口族或者套管族,毕竟插件要掏钱,那就自己码码代码生成一下吧。
原理也比较简单:
接下来看一下具体的步骤代码吧:
选择要留洞的管线
Selection selection = uiDoc.Selection;
IList<Element> elList = selection.PickElementsByRectangle(new Pub_SelectFilter.MEPSelectionFilter(), "选择管线");
List<ElementId> elidList = new List<ElementId>();//管线的ID
foreach (Element current in elList)
{
elidList.Add(current.Id);
}
获得套管类型
FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
filteredElementCollector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_GenericModel);//获得套管
FamilySymbol faSy = null;
using (IEnumerator<Element> enumerator = filteredElementCollector.GetEnumerator())
{
while (enumerator.MoveNext())
{
FamilySymbol familySymbol = (enumerator.Current) as FamilySymbol;
if (familySymbol.Family.Name == "预留洞构件_套管")
{
faSy = familySymbol;
}
}
}
由于土建一般是链接文件,先要拿到链接文件
获得和管线有碰撞的solid
FilteredElementCollector filteredElementCollector3 = new FilteredElementCollector(revitLinkInstance.GetLinkDocument());
List<ElementFilter> elFiterList = new List<ElementFilter>();
ElementCategoryFilter filter1 = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
ElementCategoryFilter filter2 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
elFiterList.Add(filter1);
elFiterList.Add(filter2);
LogicalOrFilter logOr = new LogicalOrFilter(elFiterList);
filteredElementCollector3.WherePasses(logOr);//过滤出所有的墙和梁
//过滤出所有和管线碰撞的梁和墙
List<ElementId> listSolidId = FilterWallOrBeam(el, filteredElementCollector3);
获得管线的标高
获得solid的数据
找到交点,即套管或洞口的创建点
if (listPF.Count >= 2)
{
for (int i = 0; i < listPF.Count; i++)
{
XYZ xYZnew = Class10.smethod_1(listPF[i], curve);
if (xYZnew != null)
{
xyzList.Add(xYZnew);
}
}
XYZ xYZ2 = xyzList[1];
XYZ xYZ3 = xyzList[2];
if (xYZ2 != null && xYZ3 != null)
{
xYZ = Line.CreateBound(xYZ2, xYZ3).Evaluate(0.5, true);
}
}
创建及修改套管的尺寸
familyInstance = doc.Create.NewFamilyInstance(xYZ, faSy, level1, 0);
if (familyInstance != null)
{
familyInstance.Symbol.GetParameters("D")[0].Set(numD + 70/ 304.8);
familyInstance.GetParameters("B")[0].Set(doubleWallW + 100 / 304.8);
ElementTransformUtils.RotateElement(doc, familyInstance.Id, Line.CreateBound(xYZ, new XYZ(xYZ.X, xYZ.Y, xYZ.Z + 1)), Math.PI / 2);
}
我这里的套管参数是非常随意设的,我是DN150的管子因此加了70,具体的套管大小详图集02S404,里面有很详细的介绍,或者咨询给排水工程师。