Revit二次开发小白学习笔记2——函数配置、应用类及文档类

本文介绍了Revit二次开发的基础,包括如何引用第三方库、使用RevitAPI接口函数,以及详细解释了UIApplication、Application和UIDocument、Document类的作用、获取方法和操作元素的示例。
摘要由CSDN通过智能技术生成

1.Revit二次开发函数配置

1.1.引用Revit第三方库

RevitAPI
RevitAPIUI
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Architecture;

1.2.Revit开发接口函数

[Transaction(TransactionMode.Manual)]
public class Class : IExternalCommand //Alt+Enter,内部函数自动生成
{
    //包含在此块内部的代码才能运行在Revit中,类似于Main函数
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        return Result.Succeeded;
    }
}

2.Revit 应用类:UIApplication 和 Application

2.1.注解

  • UIApplication:表示一个活动的Revit会话,提供了对UI定制、事件及活动文档的访问
  • Application:表示一个Revit应用,提供对文档、选项及其他应用范围的数据的访问和设置

2.2.获取Application/UIApplication对象

//获取Revit应用对象
UIApplication uiApp = commandData.Application;
Application App = uiApp.Application;

3.Revit文档类:UIDocument 和 Document

3.1.注解

3.1.1.UIDocument:包含根UI相关的文档信息和操作

例如:ActiveView 和 ShowElement

  • Selection:用于选择Revit模型
  • ShowElements:显示适当的元素
  • 视图管理: ①ActiveView:返回或设置当前文档的活动视图
    ②RefershActiveView:刷新当前文档的活动视图

3.1.2. Document:对象:用于存储Revit的元素、管理视图和数据

  • 类:提供获取管理元素、文件管理等功能
  • 理解:UIDocument能get和set Document只能get

3.2.获取Document/UIDocument对象

//获取视图文档名
UIDocument uIDocument = uiApp.ActiveUIDocument;
View view = uIDocument.ActiveView;
TaskDialog.Show("视图名",view.Name + ":" + view.Id.IntegerValue.ToString());
Document document = uIDocument.Document;
View view1 = document.ActiveView;
TaskDialog.Show("提示",view1.Name);

*3.3通过文档获取要素

//通过ID新建要素
ElementId id = new ElementId(13073);
//文档通过要素ID获取要素,并转化为视图

uIDocument.ActiveView = document.GetElement(id) as View;
//查看活跃视图是否修改
view1 = document.ActiveView;
TaskDialog.Show("提示","修改后活跃视图:" + view1.Name);

3.4.通过文档拉进显示要素对象

// 显示元素,会将选中的要素拉进显示
List<ElementId> list_id = new List<ElementId>();//建立要素Id列表
list_id.Add(new ElementId(201112));
list_id.Add(new ElementId(201166));
list_id.Add(new ElementId(201205));
uIDocument.ShowElements(list_id);//拉进显示要素组对象
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ping_Kingzero

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值