Revit二次开发之创建共享参数及绑定共享参数【比目鱼原创】
来源:互联网 发布:深圳市国税开票软件 编辑:程序博客网 时间:2024/05/22 04:27
=========【更多高级应用请关注公众号】========
===================================
无论是手工创建共享参数,或者用代码创建,都需要一个共享参数的文件,格式是txt,内容要按照revit定义好的模板才能正确读取。要创建这个共享参数的txt模板文件,可在“”revit-管理-共享参数-创建“”这里面操作。
手动创建并绑定共享参数的流程是:
1、创建或读取共享参数文件(txt)
2、创建共享参数组
3、创建共享参数
4、在“”revit-管理-项目参数-添加-共享参数-选择“操作,然后设置好参数分组方式,设置好绑定的类别(Category)。
PS:共享参数都是一对多的关系,也即:一个共享参数文件下可创建多个共享参数组,组下可创建多个共享参数,共享参数可自定义名称、规程、参数类型。
以下这段代码实现了创建共享参数并写入属性值。
大家也可以在我上传的代码资源中下载试用,地址是http://download.csdn.net/detail/bbkxw001/9856697,支持下
using System;using System.Linq;using System.Text;using System.Threading.Tasks;using Autodesk.Revit.DB;using Autodesk.Revit.ApplicationServices;using Autodesk.Revit.UI;using Autodesk.Revit.UI.Selection;using Autodesk.Revit.Attributes;using System.IO;using System.Reflection;using Autodesk.Revit.DB.Events;namespace CreatSharedParams{ [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class Class1 : IExternalCommand { Document _doc; UIDocument _uidoc; public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; _doc = doc; _uidoc = uidoc; var refe = uidoc.Selection.PickObject(ObjectType.Element, "Please select element"); Element selectedElement = doc.GetElement(refe) as Element; string shapeFile = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\SharedParameterFiles.txt"; this._doc.Application.SharedParametersFilename = shapeFile; Transaction trans = new Transaction(doc, "CreatSharedParams"); trans.Start(); CreatShareParam("CSDN【BIM_er】", ParameterType.Text, false, BuiltInParameterGroup.PG_TEXT, selectedElement); SetParamValue("CSDN【BIM_er】", "我开发了很多Revit插件和功能", selectedElement); trans.Commit(); return Result.Succeeded; } public bool CreatShareParam(string parameterName, ParameterType parameterType, bool canModify, BuiltInParameterGroup parameterGroup, Element element) { if (element.Category == null) { return false; } try { Application app = this._doc.Application; DefinitionFile dfile = app.OpenSharedParameterFile(); DefinitionGroup dg; if (!element.Category.AllowsBoundParameters) { return false; } Category category = element.Category; try { dg = dfile.Groups.Create("测试共享参数组"); } catch (Exception) { dg = dfile.Groups.get_Item("测试共享参数组"); } if (dg != null) { ExternalDefinitionCreationOptions edco = new ExternalDefinitionCreationOptions(parameterName, parameterType); edco.UserModifiable = canModify; Definition df; try { df = dg.Definitions.Create(edco); } catch (Exception) { df = dg.Definitions.get_Item(edco.Name); } var instanceBinding = _doc.ParameterBindings.get_Item(df) as InstanceBinding; if (instanceBinding != null) { if (!instanceBinding.Categories.Contains(category)) instanceBinding.Categories.Insert(category); _doc.ParameterBindings.ReInsert(df, instanceBinding); } else { Autodesk.Revit.DB.CategorySet categorySet = app.Create.NewCategorySet(); categorySet.Insert(category); instanceBinding = app.Create.NewInstanceBinding(categorySet); _doc.ParameterBindings.Insert(df, instanceBinding); } } return true; } catch (Exception ex) { TaskDialog.Show("error in creating parameters:", "name:" + parameterName + "\r\n" + "id:" + element.Id.ToString()); throw; } } public void SetParamValue(string parameterName, string parameterValue, Element element) { try { if (element.LookupParameter(parameterName) != null && element.LookupParameter(parameterName).IsReadOnly == false) { element.LookupParameter(parameterName).Set(parameterValue); } } catch (Exception ex) { TaskDialog.Show("Set Parameter Value Error", ex.ToString()); return; } } }}
阅读全文
0 0
- Revit二次开发之创建共享参数及绑定共享参数【比目鱼原创】
- Revit二次开发之获取参数绑定的类别【比目鱼原创】
- Revit二次开发之创建斑马线【比目鱼原创】
- Revit二次开发之创建双坡式屋顶及在屋顶开洞口【比目鱼原创】
- Revit二次开发之移动元素【比目鱼原创】
- Revit二次开发之Revit事务模式(TransactionMode)【比目鱼原创】
- Revit二次开发之如何选取Revit元素【比目鱼原创】
- Revit开发之共享参数
- Building Coder(Revit 二次开发) - 为一个共享参数绑定添加一个类别
- Revit二次开发之关于外部命令IExternalCommand【比目鱼原创】
- Revit二次开发之Journal日志文档【比目鱼原创】
- Revit二次开发之快速过滤与慢速过滤【比目鱼原创】
- Revit二次开发之材料Material的设置【比目鱼原创】
- Building Coder(Revit 二次开发) - 共享类型参数
- Revit API之如何创建梯形墙及带正反面的墙【比目鱼原创】
- Revit二次开发之外部应用IExternalApplications和数据库级别的外部应用【比目鱼原创】
- Revit二次开发之如何在addin文件定制资源【比目鱼原创】
- Revit二次开发之使用LINQ查询元素过滤集合里的元素【比目鱼原创】
- Linux搭建SVN服务器及服务端代码自动更新
- Spark Streaming+kafka订单实时统计实现
- 机房重构—注册
- golang日記
- linux 读写锁的几种实现方式
- Revit二次开发之创建共享参数及绑定共享参数【比目鱼原创】
- POJ-3735 Training little cats
- 图片缩放
- 编程之美 2.4 “1”的数目及扩展问题
- 机器学习算法~推荐系统
- 16 Quantized Convolutional Neural Networks for Mobile Devices论文翻译笔记
- Core Animation 基础
- 守护进程和守护线程
- CentOS 安装 Maven