Revit二次开发小白学习笔记1——概念及接口介绍


  将Revit二次开发入门的基本概念、接口使用方法知识点进行整理:

  • 概念:
    UIApplicationApplicationUIDocumentDocument
  • 接口函数:
    IExternalCommand接口活动窗口ActiveView拉进显示要素ShowElements单选要素Selection.PickObject多选要素Selection.PickObjects获取点Selection.PickPoint

概念:Application与Document

1、Revit 应用类:UIApplication 和 Application
   UIApplication:表示一个活动的Revit会话,提供了对UI定制、事件及活动文档的访问
   Application:表示一个Revit应用,提供对文档、选项及其他应用范围的数据的访问和设置
   理解:   
2、Revit文档类:UIDocument 和 Document
   UIDocument:包含根UI相关的文档信息和操作,例如:ActiveView 和 ShowElement
               Selection:用于选择Revit模型
               ShowElements:显示适当的元素
               视图管理:①ActiveView:返回或设置当前文档的活动视图②RefershActiveView:刷新当前文档的活动视图
   Document:对象:用于存储Revit的元素、管理视图和数据
             类:提供获取管理元素、文件管理等功能
   理解:UIDocument能getset Document只能get

接口函数:IExternalCommand与ActiveView

IExternalCommand接口

  • 固有格式,只有该结构能将我们的函数与Revit关联起来
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.ApplicationServices;
namespace Cls_RevitTest
{
	[Transaction(TransactionMode.Manual)]
    public class Class : IExternalCommand //Alt+Enter
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
       		//获取应用
            UIApplication uiApp = commandData.Application;
            Application App = uiApp.Application;
            //获取版本号,弹窗显示
            TaskDialog.Show("版本号",App.VersionName);
            //获取活动视图名及ID
            UIDocument uIDocument = uiApp.ActiveUIDocument;
            View view = uIDocument.ActiveView;
            TaskDialog.Show("视图名",view.Name + ":" + view.Id.IntegerValue.ToString());
            Document document = uIDocument.Document;
            return Result.Succeeded;
        }
    }
}

活动窗口ActiveView:

  • uIDocument获取活动文档和窗口,或者set活动视图
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.ApplicationServices;
namespace Cls_RevitTest
{
	[Transaction(TransactionMode.Manual)]
    public class Class : IExternalCommand //Alt+Enter
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
       		//获取应用
            UIApplication uiApp = commandData.Application;
            Application App = uiApp.Application;
			UIDocument uIDocument = uiApp.ActiveUIDocument;
			Document document = uIDocument.Document;
			获取要素
            ElementId id = new ElementId(13073);
            //直接对view修改无效
            //view = document.GetElement(id) as View;
            uIDocument.ActiveView = document.GetElement(id) as View;
            //查看活跃视图是否修改
            view = document.ActiveView;
            TaskDialog.Show("提示","修改后活跃视图:" + view.Name);
        }
    }
}
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ping_Kingzero

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

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

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

打赏作者

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

抵扣说明:

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

余额充值