0

此代码尝试将标签添加到天花板视图列表中的所有天花板。天花板视图列表已填充,我可以从文档中获取天花板元素,但在尝试获取天花板元素的中心点时似乎失败了。我已经用谷歌搜索了所有博客,也找不到在 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;
    }
4

2 回答 2

0

我不是专家,但你不会忘记你的 X 组件吗?

            //add tag to centre of ceiling?
            LocationPoint p = ceiling.Location as LocationPoint;
            p.Point = new XYZ(p.Point.X / 2, p.Point.Y / 2, p.Point.Z);
            ceilingCentre = p.Point;

看起来您希望Point根据 X 和 Y 将这个 p 居中,并保留 Z 分量。

于 2014-08-23T03:42:05.523 回答
0

有点晚了,但我刚刚遇到了这个。Revit 图元可以通过点(大多数族实例)、线(墙、基于线的组件)或草图(天花板、地板等)定位。您的代码将不起作用,因为您将位置投射到位置点,而它不是位置点。

使用草图,您无法将位置投射到任何有用的位置,因此您需要自己弄清楚如何确定天花板的中心。简单的答案是找到天花板的边界框并按照 mtumminello 的建议计算它的中心。这适用于大多数天花板,除非您的 L 形较大或边界框中心可能根本不在天花板上方。如果您需要涵盖此内容,则必须提出其他一些算法来找到中心点。

于 2015-03-19T20:38:26.537 回答