应用范围:EnergyAnalysisModel
Revit平台:所有
Revit版本:2012.0
首次发布日期:2012.0
编程语言:c#
技能水平:中等
类别:分析
类型:ExternalCommand
主题:EnergyAnalysisModel
摘要:这个示例是为了演示如何创建使用EnergyAnalysisModel。该项目将根据定义的选项获得能量分析模型,并通过树形视图显示面结构。
相关类:
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.Document
Autodesk.Revit.Element
Autodesk.Revit.DB;
Autodesk.Revit.DB.Analysis;
项目文件:
Command.cs
这个文件包含一个类Command,它实现了IExternalCommand接口。该类的功能是创建EnergyAnalysisModel的实例,并弹出输入和显示对话框。
EnergyAnalysisModel.cs
这个文件包含一个类EnergyAnalysisModel,它接受选项输入,从当前建筑模型中获取分析数据,并通过树视图显示表面信息。
OptionsAndAnalysisForm.cs
该文件包含一个窗口表单,允许用户进行UI输入和查看分析数据。
描述:
示例实现了IExternalCommand接口,允许用户定义能量分析选项并查看分析数据。
- 要获取分析开口信息,使用EnergyAnalysisModel的getanalytical开口方法。
- 要获得分析阴影表面信息,使用EnergyAnalysisModel的GetAnalyticalShadingSurfaces方法。
- 获取分析空间信息,使用EnergyAnalysisModel的GetAnalyticalSpaces方法。
- 查看新的分析模型,使用EnergyAnalysisModel的RefreshAnalysisData方法。
产品说明:
1. 设置插件文件并启动Revit以加载此示例。
2. 通过外部命令菜单启动EnergyAnalysis Model。
4. 输入选项,包括层值、导出mullions、incleshadingsurfaces和简化curtainsystems。单击“刷新”按钮。
6. 根据您设置的选项,样品将显示当前建筑模型的能源分析数据。您可以通过单击树形视图查看其表面信息。
7. 单击Close按钮结束energyanalysismodel。
源代码:
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
EnergyAnalysisModel.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
namespace Revit.SDK.Samples.EnergyAnalysisModel.CS
{
public class EnergyAnalysisModel
{
// An EnergyAnalysisDetailModel member that can get all analysis data includes surfaces, spaces and openings.
private EnergyAnalysisDetailModel m_energyAnalysisDetailModel;
// Options for Energy Analysis process
private EnergyAnalysisDetailModelOptions m_options;
// revit document
private Document RevitDoc;
// Options Property
public EnergyAnalysisDetailModelOptions Options
{
get
{
return m_options;
}
set
{
m_options = value;
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="doc">Revit Document</param>
public EnergyAnalysisModel(Document doc)
{
RevitDoc = doc;
m_options = new EnergyAnalysisDetailModelOptions();
}
/// <summary>
/// Get EnergyAnalysisDetailModel object and Initialize it.
/// </summary>
public void Initialize()
{
// create the model with a document and options.
m_energyAnalysisDetailModel = EnergyAnalysisDetailModel.Create(RevitDoc, m_options);
m_energyAnalysisDetailModel.TransformModel();
}
/// <summary>
/// This method get all openings surfaces from current model
/// </summary>
/// <returns>XElement that places openings surfaces</returns>
public XElement GetAnalyticalOpenings()
{
// openings for the first EnergyAnalysisDetailModel whose openings should not be merged
XElement openingsNode = new XElement("OpeningsModels");
openingsNode.Add(new XAttribute("Name", "OpeningsModels"));
// get EnergyAnalysisOpenings from Model1
IList<EnergyAnalysisOpening> openings = m_energyAnalysisDetailModel.GetAnalyticalOpenings();
foreach (EnergyAnalysisOpening opening in openings)
{
XElement openNode = new XElement("Open");
openNode.Add(new XAttribute("Name", opening.Name));
// add individual opening node to whol openings node
openingsNode.Add(openNode);
// get surfaces from opening
EnergyAnalysisSurface openingSurface = opening.GetAnalyticalSurface();
if (null == openingSurface)
continue;
XElement surfaceNode = new XElement("Surface");
surfaceNode.Add(new XAttribute("Name", openingSurface.Name));
openNode.Add(surfaceNode);
}
// return the whole openings node
return openingsNode;
}
/// <summary>
/// This method get all Analytical ShadingSurfaces from current model
/// </summary>
/// <returns>XElement that places shading surfaces</returns>
public XElement GetAnalyticalShadingSurfaces()
{
// create a node that places all shading surfaces
XElement shadingSurfacesNode = new XElement("ShadingSurfaces1");
shadingSurfacesNode.Add(new XAttribute("Name", "ShadingSurfaces"));
// get shadingSurfaces from Model
IList<EnergyAnalysisSurface> shadingSurfaces = m_energyAnalysisDetailModel.GetAnalyticalShadingSurfaces();
SurfacesToXElement(shadingSurfacesNode, shadingSurfaces);
return shadingSurfacesNode;
}
/// <summary>
/// Extract Analytical data about Space and its surfaces
/// </summary>
/// <returns>XElment that includes all data about AnalyticalSpace</returns>
public XElement GetAnalyticalSpaces()
{
// create a node that place all spaces.
XElement energyAnalysisSpacesNode = new XElement("AnalyticalSpaces");
energyAnalysisSpacesNode.Add(new XAttribute("Name", "AnalyticalSpaces"));
// get EnergyAnalysisSpaces from m_energyAnalysisDetailModel
IList<EnergyAnalysisSpace> energyAnalysisSpaces = m_energyAnalysisDetailModel.GetAnalyticalSpaces();
// get surface from each Space
foreach (EnergyAnalysisSpace space in energyAnalysisSpaces)
{
XElement spaceNode = new XElement("Space");
spaceNode.Add(new XAttribute("Name", space.ComposedName));
// add individual space node to spaces collection node
energyAnalysisSpacesNode.Add(spaceNode);
IList<EnergyAnalysisSurface> analyticalSurfaces = space.GetAnalyticalSurfaces();
SurfacesToXElement(spaceNode, analyticalSurfaces);
}
// return the whole Spaces Node
return energyAnalysisSpacesNode;
}
/// <summary>
/// The method adds given surfaces to specific XElement
/// </summary>
/// <param name="node">Parent node</param>
/// <param name="analyticalSurfaces">The surfaces list that will be added into the para node</param>
private void SurfacesToXElement(XElement node, IList<EnergyAnalysisSurface> analyticalSurfaces)
{
// go through all surfaces
foreach (EnergyAnalysisSurface surface in analyticalSurfaces)
{
XElement surfaceNode = new XElement("Surface");
surfaceNode.Add(new XAttribute("Name", surface.Name));
// add individual surface node to parent node
node.Add(surfaceNode);
}
}
/// <summary>
/// Get Analytical data and pass them to UI controls
/// </summary>
/// <param name="treeView"></param>
public void RefreshAnalysisData(TreeView treeView)
{
treeView.Nodes.Clear();
//treeView.Nodes adds first level node
TreeNode node = new TreeNode("BuildingModel");
treeView.Nodes.Add(node);
// append space surfaces node
TreeNode spaceNode = XElementToTreeNode(GetAnalyticalSpaces());
node.Nodes.Add(spaceNode);
// append opening surfaces node
TreeNode openingNode = XElementToTreeNode(GetAnalyticalOpenings());
node.Nodes.Add(openingNode);
// append shading surfaces node
TreeNode shadingNode = XElementToTreeNode(GetAnalyticalShadingSurfaces());
node.Nodes.Add(shadingNode);
}
/// <summary>
/// This method converts XElement nodes to Tree nodes so that analysis data could be displayed in UI treeView
/// </summary>
/// <param name="element">XElement to be converted</param>
/// <returns>Tree Node that comes from XElement</returns>
private TreeNode XElementToTreeNode(XElement element)
{
if (null == element.FirstAttribute)
return null;
TreeNode node = new TreeNode(element.FirstAttribute.Value);
if (!element.HasElements)
// return if it is leaf node
return node;
// convert its child elements
foreach (XElement ele in element.Elements())
{
node.Nodes.Add(XElementToTreeNode(ele));
}
// return whole node
return node;
}
/// <summary>
/// This method converts UI selected string to EnergyAnalysisDetailModelTier enum
/// </summary>
/// <param name="tierValue">Selected string from UI</param>
public void SetTier(String tierValue)
{
switch (tierValue)
{
case "Final":
m_options.Tier = EnergyAnalysisDetailModelTier.Final;
break;
case "FirstLevelBoundaries":
m_options.Tier = EnergyAnalysisDetailModelTier.FirstLevelBoundaries;
break;
case "NotComputed":
m_options.Tier = EnergyAnalysisDetailModelTier.NotComputed;
break;
case "SecondLevelBoundaries":
m_options.Tier = Autodesk.Revit.DB.Analysis.EnergyAnalysisDetailModelTier.SecondLevelBoundaries;
break;
// the default Tier is SecondLevelBoundaries
default:
m_options.Tier = Autodesk.Revit.DB.Analysis.EnergyAnalysisDetailModelTier.SecondLevelBoundaries;
break;
}
}
}
}
OptionsAndAnalysisForm.Designer.cs:
namespace Revit.SDK.Samples.EnergyAnalysisModel.CS
{
partial class OptionsAndAnalysisForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OptionsAndAnalysisForm));
this.treeViewAnalyticalData = new System.Windows.Forms.TreeView();
this.buttonRefresh = new System.Windows.Forms.Button();
this.buttonClose = new System.Windows.Forms.Button();
this.comboBoxTier = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.checkBoxExportMullions = new System.Windows.Forms.CheckBox();
this.checkBoxSimplifyCurtainSystems = new System.Windows.Forms.CheckBox();
this.checkBoxIncludeShadingSurfaces = new System.Windows.Forms.CheckBox();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// treeViewAnalyticalData
//
resources.ApplyResources(this.treeViewAnalyticalData, "treeViewAnalyticalData");
this.treeViewAnalyticalData.Name = "treeViewAnalyticalData";
//
// buttonRefresh
//
resources.ApplyResources(this.buttonRefresh, "buttonRefresh");
this.buttonRefresh.Name = "buttonRefresh";
this.buttonRefresh.UseVisualStyleBackColor = true;
this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
//
// buttonClose
//
this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
resources.ApplyResources(this.buttonClose, "buttonClose");
this.buttonClose.Name = "buttonClose";
this.buttonClose.UseVisualStyleBackColor = true;
//
// comboBoxTier
//
this.comboBoxTier.FormattingEnabled = true;
this.comboBoxTier.Items.AddRange(new object[] {
resources.GetString("comboBoxTier.Items"),
resources.GetString("comboBoxTier.Items1"),
resources.GetString("comboBoxTier.Items2"),
resources.GetString("comboBoxTier.Items3")});
resources.ApplyResources(this.comboBoxTier, "comboBoxTier");
this.comboBoxTier.Name = "comboBoxTier";
//
// label1
//
resources.ApplyResources(this.label1, "label1");
this.label1.Name = "label1";
//
// label2
//
resources.ApplyResources(this.label2, "label2");
this.label2.Name = "label2";
//
// checkBoxExportMullions
//
resources.ApplyResources(this.checkBoxExportMullions, "checkBoxExportMullions");
this.checkBoxExportMullions.Name = "checkBoxExportMullions";
this.checkBoxExportMullions.UseVisualStyleBackColor = true;
//
// checkBoxSimplifyCurtainSystems
//
resources.ApplyResources(this.checkBoxSimplifyCurtainSystems, "checkBoxSimplifyCurtainSystems");
this.checkBoxSimplifyCurtainSystems.Name = "checkBoxSimplifyCurtainSystems";
this.checkBoxSimplifyCurtainSystems.UseVisualStyleBackColor = true;
//
// checkBoxIncludeShadingSurfaces
//
resources.ApplyResources(this.checkBoxIncludeShadingSurfaces, "checkBoxIncludeShadingSurfaces");
this.checkBoxIncludeShadingSurfaces.Name = "checkBoxIncludeShadingSurfaces";
this.checkBoxIncludeShadingSurfaces.UseVisualStyleBackColor = true;
//
// label3
//
resources.ApplyResources(this.label3, "label3");
this.label3.Name = "label3";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBoxExportMullions);
resources.ApplyResources(this.groupBox1, "groupBox1");
this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false;
//
// groupBox2
//
resources.ApplyResources(this.groupBox2, "groupBox2");
this.groupBox2.Name = "groupBox2";
this.groupBox2.TabStop = false;
//
// OptionsAndAnalysisForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
resources.ApplyResources(this, "$this");
this.Controls.Add(this.label3);
this.Controls.Add(this.checkBoxSimplifyCurtainSystems);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBoxTier);
this.Controls.Add(this.checkBoxIncludeShadingSurfaces);
this.Controls.Add(this.buttonClose);
this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.treeViewAnalyticalData);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "OptionsAndAnalysisForm";
this.ShowIcon = false;
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TreeView treeViewAnalyticalData;
private System.Windows.Forms.Button buttonRefresh;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.ComboBox comboBoxTier;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.CheckBox checkBoxExportMullions;
private System.Windows.Forms.CheckBox checkBoxSimplifyCurtainSystems;
private System.Windows.Forms.CheckBox checkBoxIncludeShadingSurfaces;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
}
}
版权所有 :无锡模信建筑科技有限公司 苏ICP备2021028830号-1 BIM建模|BIM技术应用|BIM软件开发
联系地址:江苏省无锡市新吴区龙山路4号B座705 手机:18761516598