2011-07-12 89 views
2

我有這樣的代碼,我不知道我怎麼可以顯示的位置,高度,我的選擇牆的長度:Revit中,如何讓位置,長度和高度在選擇牆

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; 
     } 
    } 
} 

回答

4

壁的位置是基於它的駕駛曲線,從壁作爲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 

這是一個標準的牆壁,並且不會適用於特殊壁類型,如幕牆以及堆疊壁。

+0

小心位置曲線。它實際上只提供牆壁中心線,因此端點通常最終位於角落關節的中間,而不一定是牆的端點。 – sweetfa

相關問題