应用程序:BeanAndSlabNewParameter
Revit平台:所有
Revit版本:2011.0
首次发布用于:9.0
编程语言:C#
技能等级:中等
类别:参数
类型:ExternalCommand
主题:共享参数。
摘要:此示例演示如何将共享实例参数添加到梁和楼板,并使用GUID作为参数值。用户还可以使用参数的值来查找特殊元素。
相关类:
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.DefinitionFile
Autodesk.Revit.DB.DefinitionGroups
Autodesk.Revit.DB.DefinitionGroup
Autodesk.Revit.DB.Definitions
Autodesk.Revit.DB.Definition
Autodesk.Revit.DB.CategorySet
Autodesk.Revit.DB.InstanceBinding
Autodesk.Revit.DB.Parameter
Autodesk.Revit.UI.Selection.SelElementSet
项目文件:
BeanAndSlabNewParameter.cs这是主DLL源文件。它包含类Command,该类实现接口IExternalCommand,并实现添加共享参数、存储GUID值和查找元素功能。
BeanAndSlabNewParameterForm.cs此文件包含一个类BeanAndSlab NewParameterForm,该类提供用户交互UI。
功能:
-此示例中添加共享参数的功能对应于Revit主程序中的“管理->项目参数…->添加->共享参数(单选按钮)->选择”。如果需要有关共享参数的详细信息,请参阅Revit帮助文档中的“设置共享参数”主题。
-应将名为“唯一ID”的共享参数添加到“结构框架”和“楼板”类别中,以便它可以覆盖梁和楼板。然后应该将Unique id设置为系统生成的UUID。
-共享参数应位于名为MySharedParameters.txt的文件和名为MyParameters的参数组中。如果该文件不存在,则应创建该文件。如果它确实存在,那么应该重用它。
-在列表框中显示所有选定图元的“唯一ID”参数的值(如果存在)。
-元素应该通过列表框中列出的GUID找到。在这个示例中,我们将找到的元素添加到SelElementSet(Document.Selection.Elements)中,使其高亮显示。
实施:
1.在Revit中绘制梁和板,然后运行命令。
2.首先单击此示例UI中的“添加”按钮。
3.返回Revit后,选择一些梁和板。
4.然后再次运行此命令,然后单击“显示值”按钮。
5.在左侧列表框中选择一个项目,然后单击“查找”按钮。
6.预期结果:返回Revit主程序。唯一ID与所选项目相同的相应元素将高亮显示。
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
BeanAndSlabNewParameter.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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
namespace Revit.SDK.Samples.AvoidObstruction.CS
{
/// <summary>
/// This class presents an obstruction of a Pipe.
/// </summary>
class Section
{
/// <summary>
/// Pipe centerline's direction.
/// </summary>
private Autodesk.Revit.DB.XYZ m_dir;
/// <summary>
/// Extend factor in negative direction.
/// </summary>
private double m_startFactor;
/// <summary>
/// Extend factor in positive direction.
/// </summary>
private double m_endFactor;
/// <summary>
/// References contained in this obstruction.
/// </summary>
private List<ReferenceWithContext> m_refs;
/// <summary>
/// Pipes to avoid this obstruction, it is assigned when resolving this obstruction.
/// Its count will be three if resolved, the three pipe constructs a "U" shape to round the obstruction.
/// </summary>
private List<Pipe> m_pipes;
/// <summary>
/// Private constructor, just be called in static factory method BuildSections.
/// </summary>
/// <param name="dir">Pipe's direction</param>
private Section(Autodesk.Revit.DB.XYZ dir)
{
m_dir = dir;
m_startFactor = 0;
m_endFactor = 0;
m_refs = new List<ReferenceWithContext>();
m_pipes = new List<Pipe>();
}
/// <summary>
/// Pipe centerline's direction.
/// </summary>
public Autodesk.Revit.DB.XYZ PipeCenterLineDirection
{
get { return m_dir; }
}
/// <summary>
/// Pipes to avoid this obstruction, it is assigned when resolving this obstruction.
/// Its count will be three if resolved, the three pipe constructs a "U" shape to round the obstruction.
/// </summary>
public List<Pipe> Pipes
{
get { return m_pipes; }
}
/// <summary>
/// Start point of this obstruction.
/// </summary>
public Autodesk.Revit.DB.XYZ Start
{
get
{
return m_refs[0].GetReference().GlobalPoint + m_dir * m_startFactor;
}
}
/// <summary>
/// End point of this obstruction.
/// </summary>
public Autodesk.Revit.DB.XYZ End
{
get
{
return m_refs[m_refs.Count - 1].GetReference().GlobalPoint + m_dir * m_endFactor;
}
}
/// <summary>
/// References contained in this obstruction.
/// </summary>
public List<ReferenceWithContext> Refs
{
get { return m_refs; }
}
/// <summary>
/// Extend this obstruction's interval in one direction.
/// </summary>
/// <param name="index">index of direction, 0 => start, 1 => end</param>
public void Inflate(int index, double value)
{
if (index == 0)
{
m_startFactor -= value;
}
else if(index == 1)
{
m_endFactor += value;
}
else
{
throw new ArgumentOutOfRangeException("Index should be 0 or 1.");
}
}
/// <summary>
/// Build sections for References, it's a factory method to build sections.
/// A section contains several points through which the ray passes the obstruction(s).
/// for example, a section may contain 2 points when the obstruction is stand alone,
/// or contain 4 points if 2 obstructions are intersects with each other in the direction of the ray.
/// </summary>
/// <param name="allrefs">References</param>
/// <param name="dir">Pipe's direction</param>
/// <returns>List of Section</returns>
public static List<Section> BuildSections(List<ReferenceWithContext> allrefs, Autodesk.Revit.DB.XYZ dir)
{
List<ReferenceWithContext> buildStack = new List<ReferenceWithContext>();
List<Section> sections = new List<Section>();
Section current = null;
foreach (ReferenceWithContext geoRef in allrefs)
{
if (buildStack.Count == 0)
{
current = new Section(dir);
sections.Add(current);
}
current.Refs.Add(geoRef);
ReferenceWithContext tmp = Find(buildStack, geoRef);
if (tmp != null)
{
buildStack.Remove(tmp);
}
else
buildStack.Add(geoRef);
}
return sections;
}
/// <summary>
/// Judge whether a Reference is already in the list of Reference, return the founded value.
/// </summary>
/// <param name="arr">List of Reference</param>
/// <param name="entry">Reference to test</param>
/// <returns>One Reference has the same element's Id with entry</returns>
private static ReferenceWithContext Find(List<ReferenceWithContext> arr, ReferenceWithContext entry)
{
foreach (ReferenceWithContext tmp in arr)
{
if (tmp.GetReference().ElementId == entry.GetReference().ElementId)
{
return tmp;
}
}
return null;
}
}
}
版权所有 :无锡模信建筑科技有限公司 苏ICP备2021028830号-1 BIM建模|BIM技术应用|BIM软件开发
联系地址:江苏省无锡市新吴区龙山路4号B座705 手机:18761516598