应用程序名称: SpatialFieldGradient
Revit 平台: 所有
Revit 版本: 2011.0
首次发布版本: 2011.0
编程语言: C#
技能级别: 高级
类别: 几何
类型: ExternalCommand
主题: 在 Revit 模型中显示分析结果。
概要: 选择一个面并在该面上显示数值数据。
相关类:
Autodesk.Revit.DB.Analysis.AnalysisDisplayColoredSurfaceSettings
Autodesk.Revit.DB.Analysis.AnalysisDisplayColorSettings
Autodesk.Revit.DB.Analysis.AnalysisDisplayLegendSettings
Autodesk.Revit.DB.Analysis.AnalysisDisplayStyle
Autodesk.Revit.DB.Analysis.FieldDomainPointsByUV
Autodesk.Revit.DB.Analysis.FieldValues
Autodesk.Revit.DB.Analysis.SpatialFieldManager
Autodesk.Revit.DB.FilteredElementCollector
Autodesk.Revit.DB.TextNoteType
Autodesk.Revit.DB.BoundingBoxUV
Autodesk.Revit.UI.Selection.Selection
项目文件:
Command.cs
描述:
1. 创建一个 AnalysisDisplayColoredSurfaceSettings 对象,并设置其在表面上显示网格线。
2. 创建一个 AnalysisDisplayColorSettings 对象,并设置最小和最大颜色。
3. 创建一个 AnalysisDisplayLegendSettings 对象,并指定各种图例设置。
4. 使用前面创建的设置创建一个 Analysis Display 样式。
5. 将活动视图设置为使用此 Analysis Display 样式。
6. 创建一个列表(measureNames),以便每个数据点可以存储多个值。
7. 创建列表(unitNames 和 multipliers),以便数据可以以英尺和英寸的形式显示。
8. 当选择一个面时
a. 将面的 U 和 V 参数化划分为每个方向 10 个线段。
b. 基于每个点的面的 U 值创建三个值(U、U +1、U * 10)。
9. 更新空间场原语以在面上显示此数据。
说明:
1. 运行外部命令。
2. 选择一个面。
源代码:
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
//
// (C) Copyright 2003-2019 by Autodesk, Inc. All rights reserved.
//
// 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 ITS 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.Linq;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.AnalysisVisualizationFramework.CS
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class SpatialFieldGradient : IExternalCommand
{
static AddInId m_appId = new AddInId(new Guid("CF099951-E66B-4a35-BF7F-2959CA87A42D"));
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
ExternalCommandData cdata = commandData;
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Transaction trans = new Transaction(doc, "Revit.SDK.Samples.AnalysisVisualizationFramework");
trans.Start();
SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView);
if (sfm == null) sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1);
IList<Reference> refList = new List<Reference>();
refList = uiDoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Face);
foreach (Reference reference in refList)
{
IList<UV> uvPts = new List<UV>();
List<double> doubleList = new List<double>();
IList<ValueAtPoint> valList = new List<ValueAtPoint>();
Face face = doc.GetElement(reference).GetGeometryObjectFromReference(reference)as Face;
BoundingBoxUV bb = face.GetBoundingBox();
UV min = bb.Min;
UV max = bb.Max;
for (double u = min.U; u < max.U; u += (max.U - min.U) / 10)
{
for (double v = min.V; v < max.V; v += (max.V - min.V) / 10)
{
UV uv = new UV(u, v);
if (face.IsInside(uv))
{
uvPts.Add(uv);
doubleList.Add(v + DateTime.Now.Second);
valList.Add(new ValueAtPoint(doubleList));
doubleList.Clear();
}
}
}
FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts);
FieldValues vals = new FieldValues(valList);
int idx = sfm.AddSpatialFieldPrimitive(reference);
AnalysisResultSchema resultSchema = new AnalysisResultSchema("Schema 1", "Schema 1 Description");
sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, sfm.RegisterResult(resultSchema));
}
trans.Commit();
return Result.Succeeded;
}
}
}