【问题标题】:Revit, how to get position, length and height in a selected wallRevit,如何在选定的墙上获取位置、长度和高度
【发布时间】:2011-10-03 16:07:15
【问题描述】:

我有这段代码,但我不知道如何显示所选墙的位置、高度和长度:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace PickSelectionFiltered
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)] 

    public class Class1: IExternalCommand
    {
        public class MySelectionFilter : ISelectionFilter
        {
            Document m_doc = null;

            public bool AllowElement(Element element)
            {
                return element is Wall;
            }
            public bool AllowReference(Reference refer, XYZ point)
            {
                GeometryObject geoObject = 
                m_doc.GetElement(refer)
                     .GetGeometryObjectFromReference(refer);
                return geoObject != null && geoObject is Face;
            }
        }


        public Result Execute(ExternalCommandData commandData, 
          ref string message, ElementSet elements)
        {
            //Get application and document objects
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            try
            {
                while (true)
                {
                    Reference selRef = 
                      uidoc.Selection.PickObject(ObjectType.Element, 
                        new MySelectionFilter(), "select a room");
                    /*
                     * Add the code to get position, lenght and height
                     * */
                }

            } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }

            return Result.Succeeded;
        }
    }
}

【问题讨论】:

    标签: c# parameters get project revit


    【解决方案1】:

    墙的位置是基于它的驱动曲线,从墙上作为 LocationCurve 获得的:

    Wall wall = document.GetReference(setRef) as Wall;
    if (wall != null)
    {
        LocationCurve locationCurve = wall.Location as LocationCurve;
        XYZ endPoint0 = locationCurve.Curve.get_EndPoint[0];
        XYZ endPoint1 = locationCurve.Curve.get_EndPoint[1];
    } 
    

    墙的长度由墙的参数得到:

    BuiltInParameter.CURVE_ELEM_LENGTH
    

    墙的宽度由墙类型的参数获得:

    BuiltInParameter.WALL_ATTR_WIDTH_PARAM
    

    这适用于标准墙,不适用于幕墙和叠墙等特殊墙类型。

    【讨论】:

    • 小心位置曲线。它实际上只提供墙中心线,因此端点通常最终位于角接头的中间,不一定是墙的端点。
    猜你喜欢
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多