zoukankan      html  css  js  c++  java
  • revit二次开发之四 获取元素的分析模型

    分析模型主要被用来做结构分析,所以只有结构墙、结构柱等结构族才具有分析模型线,获取分析模型线,可以通过使用Element.GetAnalyticalModel()获得,然后调用分析模型的GetCurve或者GetPoint来获取分析模型的几何信息。此外,可以通过IsSingleCurve和IsSinglePoint来判断需要调用的方法。

    AnalyticalModel在命名空间  Autodesk.Revit.DB.Structure中,其有两个子类

    AnalyticalModelStick :标识分析模型线中的一个杆件,他可以用来表示一个梁、柱和支撑等。

    AnalyticalModelColumn AnalyticalModelStick 的子类,标识一个柱

    AnalyticalModelSurface :表示一个分析模型表面,如墙。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Autodesk.Revit;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.UI.Selection;
    using Autodesk.Revit.DB.Structure;
    using System.Linq;
    
    namespace Revit.SDK.Samples.HelloRevit.CS
    {
        public class Command : IExternalCommand
        {
    
            public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                ref string message, Autodesk.Revit.DB.ElementSet elements)
            {
              
                Application app = commandData.Application.Application;
                Document activeDoc = commandData.Application.ActiveUIDocument.Document;
                ICollection<ElementId> collection = new List<ElementId>();
           
    
               List<Reference> pickReferences=commandData.Application.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "拾取所有元素").ToList();
    
               pickReferences.ForEach(x=>collection.Add(x.ElementId));
    
    
               TaskDialog Task = new TaskDialog("显示模型线的种类");
               foreach (ElementId eId in collection)
                {
                    Element ele= activeDoc.GetElement(eId);
                    AnalyticalModel am = ele.GetAnalyticalModel();
                    if (am != null)
                    {
                        Task.MainContent += "结构类型:" + ele.GetType().Name + "分析模型线类型:" + am.GetType().Name+"
    ";
                    }
    
                }
               Task.Show();
    
                return Autodesk.Revit.UI.Result.Succeeded;
            }
    
    
        }
    }
    获取分析模型线的类型

    如何获取模型线的是线还是点,可以通过如下方法:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Autodesk.Revit;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.UI.Selection;
    using Autodesk.Revit.DB.Structure;
    using System.Linq;
    
    namespace Revit.SDK.Samples.HelloRevit.CS
    {
        public class Command : IExternalCommand
        {
    
            public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                ref string message, Autodesk.Revit.DB.ElementSet elements)
            {
    
                Application app = commandData.Application.Application;
                Document activeDoc = commandData.Application.ActiveUIDocument.Document;
                ICollection<ElementId> collection = new List<ElementId>();
    
                //获取所有选择对象的引用
                List<Reference> pickReferences = commandData.Application.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "拾取所有元素").ToList();
    
                pickReferences.ForEach(x => collection.Add(x.ElementId));
    
    
                TaskDialog Task = new TaskDialog("显示模型线的种类");
    
                foreach (ElementId eId in collection)
                {
                    Element ele = activeDoc.GetElement(eId);
                    //获取分析模型线
                    AnalyticalModel am = ele.GetAnalyticalModel();
                    if (am != null)
                    {
                        Task.MainContent += "结构类型:" + ele.GetType().Name + "分析模型线类型:" + am.GetType().Name + "
    ";
                    }
                    //只是一条线
                    if (am.IsSingleCurve()) {
    
                        Curve curve = am.GetCurve();
                    }
                     //只是一个点
                    else if (am.IsSinglePoint())
                    {
    
                        XYZ p = am.GetPoint();
                    }
                    //是一个面
                    else {
                        IList<Curve> curves = am.GetCurves(AnalyticalCurveType.ActiveCurves);
                    }
                }
                Task.Show();
    
                return Autodesk.Revit.UI.Result.Succeeded;
            }
    
    
        }
    }
    获取分析模型线的的种类
  • 相关阅读:
    面向对象与组合
    异常处理和三级菜单练习
    装饰器和生成器
    序列化模块
    leetcode_498. 对角线遍历
    leetcode_566. 重塑矩阵
    leetcode_59. 螺旋矩阵 II
    leetcode_54. 螺旋矩阵
    leetcode_396. 旋转函数
    leetcode_200. 岛屿数量
  • 原文地址:https://www.cnblogs.com/minhost/p/5787749.html
Copyright © 2011-2022 走看看