Revit简单插件

  • 窗体设计
  • 代码编写

流程:创建windows窗体应用-》配置Revit类库引用-》窗体设计-》代码编写-》编译运行

窗体设计


在工具箱中选择控件

在窗口中添加控件

点击控件可以修改代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace SelectionDemo
{public partial class Form1 : Form{public Form1(string idsText = ""){InitializeComponent();textBox1.Text = idsText;}private void label1_Click(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){this.DialogResult = DialogResult.OK;this.Close();}}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Form = System.Windows.Forms.Form;using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;namespace SelectionDemo
{public partial class Form2 : Form{private Document doc;public Form2(Document doc){this.doc = doc;InitializeComponent();}private void label1_Click(object sender, EventArgs e){}private void button2_Click(object sender, EventArgs e){this.button1_Click(sender, e);this.DialogResult = DialogResult.OK;this.Close();}private void button1_Click(object sender, EventArgs e){//选集有效性检查if (null != RevitSelection && RevitSelection.IsValidObject){RevitSelection.SetElementIds(new List<ElementId>());string[] idTexts = textBox1.Text.Trim().Split(',');string error = "将不使用下列无效图元 ID:";bool hasError = false;ICollection<ElementId> selIds = new List<ElementId>();for (int i = 0; i < idTexts.Length; i++){int id = 0;if (!int.TryParse(idTexts[i], out id) || this.doc.GetElement(new ElementId(id)) == null){hasError = true;error += idTexts[i] + ",";}else{selIds.Add(new ElementId(id));}}if (hasError){error = error.Remove(error.Count() - 1) + ";";TaskDialog.Show("Revit", error);}RevitSelection.SetElementIds(selIds);if (RevitSelection.GetElementIds().Count == 0){TaskDialog.Show("Revit", "未找到完好的视图");}}}private void button3_Click(object sender, EventArgs e){this.DialogResult = DialogResult.Cancel;this.Close();}public Selection RevitSelection { get; set; }}
}

代码编写

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using Autodesk.Revit.DB;
using Autodesk.Revit.UI;namespace SelectionDemo
{[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]public class IdsOfSelectionCmd : IExternalCommand{public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){try{ICollection<ElementId> selIds = commandData.Application.ActiveUIDocument.Selection.GetElementIds();if (0 != selIds.Count){string idsText = string.Empty;string spliter = ",";foreach (ElementId eleId in selIds){idsText += eleId.ToString() + spliter;}System.Windows.Forms.Form fm = new Form1(idsText.Remove(idsText.Length - 1));fm.ShowDialog();}return Autodesk.Revit.UI.Result.Succeeded;}catch (Exception ex){message = ex.Message;return Autodesk.Revit.UI.Result.Failed;}}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace SelectionDemo
{[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]public class SelectByIdCmd : IExternalCommand{public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){try{UIDocument uidoc = commandData.Application.ActiveUIDocument;Form2 fm = new Form2(uidoc.Document);fm.RevitSelection = uidoc.Selection;fm.ShowDialog();return Autodesk.Revit.UI.Result.Succeeded;}catch (Exception ex){message = ex.Message;return Autodesk.Revit.UI.Result.Failed;}}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using Autodesk.Revit.UI;namespace SelectionDemo
{public class SelectionApp : IExternalApplication{public Autodesk.Revit.UI.Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application){try{string assemblyPath = @"D:\培训资料\test\SelectionDemo\bin\Debug\SelectionDemo.exe";RibbonPanel panel = application.CreateRibbonPanel("查询");string nmspace = "SelectionDemo.";// 节点面板控件集合panel.AddStackedItems(new PushButtonData("btn_idToElement", "按ID选择", assemblyPath, nmspace + "SelectByIdCmd"){},new PushButtonData("btn_ElementToId", "选择项的ID", assemblyPath, nmspace + "IdsOfSelectionCmd"){});return Result.Succeeded;}catch{return Result.Failed;}}public Autodesk.Revit.UI.Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application){return Result.Succeeded;}}
}

Revit二次开发——一个简单的插件相关推荐

  1. Revit二次开发——设备自动接管插件的开发思路(入门实例教程)

    前文提及 使用翻模插件进行前期建模工作 是效率较高的工作模式 用翻模软件 对水暖管线翻模 简直爽到爆炸 解放劳动力刷知乎/强 本文介绍--管道与终端设备的自动接管插件开发思路 (以水管与风机盘管连接为 ...

  2. rails开发利器:视频播放插件plugin(如何开发一个简单的插件)

    For: rails2.3.8   因为我的项目是基于rails2.3.8的,以后在做rails3.0的 plugin的名称是 video_player, 新建plugin ruby script/g ...

  3. 【Revit二次开发】“附加模块”中添加“外部工具”AND外部工具中添加新建插件

    写在前面,今天第一次接触Revit二次开发,要做的两件事情 第一,搭建环境(安装的是破解版2017的Revit软件.下载SDK2017的并安装.还有开发平台VS2015). 第二,首先就是运行Hell ...

  4. 使用NSIS制作多版本Revit插件(Revit二次开发)

    因为VisualStudio中微软官方的程序打包工具,无法实现Revit多版本插件的制作,所以我选择了NSIS来制作多版本插件. 一.使用NSIS向导创建脚本 1.1.打开NSIS的VNISEdit( ...

  5. Revit 二次开发 未能加载文件或程序集“Microsoft.Xaml.Behaviors”或它的某一个依赖项

    写了几个WPF界面,在addinmangager时没有发现问题,当编到一个addin文件中打包时,报错 未能加载文件或程序集"Microsoft.Xaml.Behaviors, Public ...

  6. Revit二次开发——族库管理插件的开发思路

    Revit二次开发--族库管理插件的开发思路 成熟的BIM团队都会有自己的族库及项目样板文件 在项目样板中载入常用的族及配置好管道系统为项目节约了初始环节的时间 然鹅,项目开展阶段仍需载入新的族 或是 ...

  7. Revit二次开发从入门到精通学习之路, (含Revit二次开发教程下载)

    Revit二次开发从入门到精通学习之路 Autodesk Joe Ye叶雄进 2. 18 2014    yexiongjin@hotmail.com Revit在国内的应用越来越广泛, Revit ...

  8. Revit 二次开发之安装包的制作

    做了一段时间的Revit二次开发了,也做了好几个插件,最终都不得不面临一个问题,交付客户使用,那么问题来了,客户端那边如何部署呢,最简单的方法就是让客户找到Revit插件加载目录,将我们制作的插件dl ...

  9. Revit二次开发——Ribbon菜单的创建以及各种不同的button(按钮)的代码总结

    目录 一.创建普通的一个panel里面三个32px*32px的pushbutton,剩下两个写法一样 二.创建三个层叠按钮 层叠按钮图标需为16px*16px 层叠按钮最多为一列放三个,这个也要创建个 ...

  10. Revit二次开发有几种方式?做Revit二次开发的必看!

    Revit二次开发有三种方式:外部命令(IExternalCommand).外部应用(IExternalApplication)和宏(Macro).下面将简要说明外部应用.宏的开发过程,并着重说明外部 ...

最新文章

  1. python编程输入标准-青少年Python编程能力标准等级模拟考试
  2. Xcode 中的IOS工程模板
  3. 运筹学最优化理论系列概念-单纯形法原理解析
  4. JSP response request 中文乱码
  5. 操作系统(三)内存管理
  6. pythonmessage用法_请问Mac下如何用python读取iMessage信息?
  7. 缓存设计方案 你了解吗 SpringBoot 快速集成实现一级缓存Redis和二级缓存Caffeine 可自定义扩展
  8. linux root 设置中文,ubuntu 8.04 root用户下的中文环境配置-Linux频道-中国IT实验室
  9. SQL Server中数据透视表的Python脚本
  10. 强制应用 AMP 工具,开发者欲“封杀” Google!
  11. 错误代码:ERR_UNSAFE_PORT
  12. java 内存 堆 栈 方法区 常量池
  13. 【aliplayer】阿里播放器的使用
  14. 图解计算机基础网站上线了
  15. php情书之笛卡尔的情书,笛卡尔情书的秘密——心形函数的作图
  16. 以太网未识别的网络问题
  17. openPGP加密解密
  18. Sqlite3内存数据库
  19. 辛普森悖论和朴素贝叶斯
  20. 解决:whm搬站出现的mysql error message:Can't find any matching row in the user table

热门文章

  1. 千年3 『自动杀猪·无限挂』千年3脚本 千年3外挂
  2. 光耦驱动单向可控硅_超低功耗光电耦合驱动单向可控硅电路,光电耦合器
  3. 从零开始的FPGA学习5-同步复位D触发器、异步复位D触发器
  4. Quartus II三种方式实现D触发器
  5. 控制教程 —— 介绍篇:6.状态空间控制器设计
  6. matlab灵敏度分析绘图——道路最大通行能力
  7. MFC 通用对话框之颜色对话框
  8. listview 分页加载
  9. Android开发环境的搭建教程
  10. 我的Windows Server 2008激活