2

I have this code and I don't know how I can display the position, the height, and the length of my selected wall:

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;
        }
    }
}
skeletank
  • 2,880
  • 5
  • 43
  • 75
NewBee
  • 21
  • 1
  • 2

1 Answers1

4

The position of the wall is based on it's driving curve, obtained from the wall as a 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];
} 

The length of the wall is obtained from the wall's parameter:

BuiltInParameter.CURVE_ELEM_LENGTH

The width of the wall is obtained from the wall type's parameter:

BuiltInParameter.WALL_ATTR_WIDTH_PARAM

This is for a standard wall, and would not be applicable to special wall types like curtain walls and stacked walls.

Zoinks
  • 810
  • 7
  • 4
  • Be cautious of the location curve. It actually only provides the wall centreline and therefore the endpoints usually end up in the middle of a corner joint, not necessarily the endpoints of a wall. – sweetfa Sep 26 '12 at 04:13