• Revit API取得系统族普通族几何信息的方法


    系统族,可以直接转化为对应的类(Wall,Duct)然后取得几何信息,普通族需要转化为FamilyInstance
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;

    using Autodesk.Revit.DB;


    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class GetWallBFace : IExternalCommand
    {
      public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
      {

        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;

        //select a wall      
        Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a wall");
        Element elem = doc.GetElement(ref1);
        Wall wall = elem as Wall;

        Options opt = new Options();
        opt.ComputeReferences = true;
        opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;

        GeometryElement e = wall.get_Geometry(opt);//系统族的Geometry可以直接获取

        foreach (GeometryObject obj in e.Objects)
        {
          Solid solid = obj as Solid;
          if (solid != null && solid.Faces.Size > 0)//实体必须做这样的判断,因为有可能是假的。        
            FindBottomFace(solid);
        }

        return Result.Succeeded;
      }

      Face FindBottomFace(Solid solid)
      {
        PlanarFace pf = null;
        foreach (Face face in solid.Faces)
        {
          pf = face as PlanarFace;//转化为立面平面
          if (null != pf)
          {
            //判断向量的方法:转化为Normal然后以绝对值判断(0,0,-1)
            if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
            {
              TaskDialog.Show("Wall Bottom Face""Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + "  " + pf.Origin.Y.ToString() + "  " + pf.Origin.Z.ToString() + ")");

              break;
            }
          }
        }
        return pf;
      }

    }


    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class GetColumnBottomFace : IExternalCommand
    {
      public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
      {

        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;

        //select a column      
        Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick a column");
        Element elem = doc.GetElement(ref1);
        FamilyInstance column = elem as FamilyInstance;//柱是族实例

        Options opt = new Options();
        opt.ComputeReferences = true;
        opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;

        GeometryElement e = column.get_Geometry(opt);

        foreach (GeometryObject obj in e.Objects)
        {
          //被切割的族有Solid
          if (obj is Solid)
          {
            Solid solid = obj as Solid;
            FindBottomFace(solid);
          }
          else if (obj is GeometryInstance)//取得族实例几何信息的方法
          {
            GeometryInstance geoInstance = obj as GeometryInstance;
            GeometryElement geoElement = geoInstance.GetInstanceGeometry();
            foreach (GeometryObject obj2 in geoElement.Objects)
            {
              if (obj2 is Solid)
              {
                Solid solid2 = obj2 as Solid;
                if (solid2.Faces.Size > 0)
                  FindBottomFace(solid2);
              }
            }
          }
        }
        return Result.Succeeded;
      }

      Face FindBottomFace(Solid solid)
      {
        PlanarFace pf = null;
        foreach (Face face in solid.Faces)
        {
          pf = face as PlanarFace;
          if (null != pf)
          {
            if (Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
            {
              TaskDialog.Show("column Bottom Face""Area is " + pf.Area.ToString() + "; Origin = (" + pf.Origin.X.ToString() + "  "  +pf.Origin.Y.ToString() + "  " + pf.Origin.Z.ToString() + ")");
              
              break;
            }
          }
        }
        return pf;
      }

    }

    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class GetWallBottomFace : IExternalCommand
    {
      public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
      {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;

        //select a wall
        Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Pick a wall");
        Element elem = doc.GetElement(ref1);
        Wall wall = elem as Wall;

        Options opt = new Options();
        opt.ComputeReferences = true;
        opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;

        GeometryElement e = wall.get_Geometry(opt);
        foreach (GeometryObject obj in e.Objects)
        {
          Solid solid = obj as Solid;
          if (solid != null && solid.Faces.Size > 0)
          {
            FindBottomFaces(solid);
          }
        }

        return Result.Succeeded;
      }

      Face FindBottomFaces(Solid solid)
      {
        PlanarFace pf = null;
        foreach (Face face in solid.Faces)
        {
          pf = face as PlanarFace;
          if(null != pf)
          {
            if(Math.Abs(pf.Normal.X) < 0.01 && Math.Abs(pf.Normal.Y) < 0.01 && pf.Normal.Z < 0)
            {
              TaskDialog.Show("the bottom face's area is ",  pf.Area.ToString());
            }
          }
        }
        return pf;
      }
    }
    end
  • 相关阅读:
    inflate, findViewById与setContentView的差别与联系
    Android_程序未处理异常的捕获与处理
    八皇后问题
    兔子--改动Android Studio的快捷键,改动成eclipse的快捷键
    关于cocos2d-x 和安卓之间的相互调用
    《JavaScript》——DOM
    *Android 多线程下载 仿下载助手
    (LeetCode)两个链表的第一个公共节点
    MVC初了解
    URL编码总结
  • 原文地址:https://www.cnblogs.com/greatverve/p/GeometryElement.html
Copyright © 2020-2023  润新知