此代码尝试将标签添加到天花板视图列表中的所有天花板。天花板视图列表已填充,我可以从文档中获取天花板元素,但在尝试获取天花板元素的中心点时似乎失败了。我已经用谷歌搜索了所有博客,也找不到在 revit 中标记楼层的参考,因为它可能是类似的场景。
public IndependentTag CreateIndependentTag(Document doc)
{
List<View> viewList = ceilingViewCollector(doc);
foreach (View view in viewList)
{
// Find all ceiling elements in the document by using category filter
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Ceilings);
// Use shortcut WhereElementIsNotElementType() to find ceiling instances only
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> CeilingList = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
foreach (Ceiling ceiling in CeilingList)
{
TaskDialog.Show("Ceiling", ceiling.Name);
// define tag mode and tag orientation for new tag
TagMode tagMode = TagMode.TM_ADDBY_CATEGORY;
TagOrientation tagorn = TagOrientation.Horizontal;
//add tag to centre of ceiling?
LocationPoint p = ceiling.Location as LocationPoint;
p.Point = new XYZ(0.0, p.Point.Y, p.Point.Z);
ceilingCentre = p.Point;
string coords = "point = " + ceilingCentre.ToString();
TaskDialog.Show("Source room Center", coords);
IndependentTag newTag = doc.Create.NewTag(view, ceiling, true, tagMode, tagorn, ceilingCentre);
if (null == newTag)
{
throw new Exception("Create IndependentTag Failed.");
}
// set leader mode free
// otherwise leader end point move with elbow point
newTag.LeaderEndCondition = LeaderEndCondition.Free;
XYZ elbowPnt = ceilingCentre + new XYZ(5.0, 5.0, 0.0);
newTag.LeaderElbow = elbowPnt;
XYZ headerPnt = ceilingCentre + new XYZ(10.0, 10.0, 0.0);
newTag.TagHeadPosition = headerPnt;
return newTag;
}
}
return null;
}