revit二次开发笔记创建标高

该博客介绍了如何通过WPF窗口应用与Revit进行交互,实现Revit插件来创建标高。代码示例中展示了如何利用Autodesk.Revit.ApplicationServices和Autodesk.Revit.Attributes等库,在手动交易模式下创建并命名标高,同时创建楼层平面视图。用户界面由WPF窗口提供,允许用户输入标高高度和名称,然后将这些信息用于创建Revit的Level对象。
摘要由CSDN通过智能技术生成

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CreateLevel
{
    [TransactionAttribute(TransactionMode.Manual)]
    class CreateLevel : IExternalCommand
    {
        Document document = null;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Application application = uiApp.Application;
            UIDocument uIDocument = uiApp.ActiveUIDocument;

            document = uIDocument.Document;
            using (Transaction transaction = new Transaction(document, "创建标高"))
            {
                transaction.Start();
                MainWindow mainWindow = new MainWindow();
                mainWindow.ShowDialog();
                //按点×关闭
                if (!mainWindow.ClickClosed)
                {
                    return Result.Cancelled;
                }

                double hight = Convert.ToDouble(mainWindow.hight.Text);
                String name= mainWindow.name.Text;
                Level level = LevelCreate(hight);

                level.Name = name;
                transaction.Commit();
            }
            return Result.Succeeded;
        }

        public Level LevelCreate(double var)
        {
            //创建标高
            Level level = Level.Create(document, ToFoot(var));
            //获取楼层平面
            FilteredElementCollector collector = new FilteredElementCollector(document);
            IList<Element> elements1 = collector.OfClass(typeof(ViewFamilyType)).ToElements();
            ViewFamilyType viewFamilyType = null;
            foreach (Element item in elements1)
            {
                viewFamilyType = item as ViewFamilyType;
                if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan)
                {
                    break;
                }
            }


            //创建视图
            ViewPlan viewPlan = ViewPlan.Create(document, viewFamilyType.Id, level.Id);
            return level;
        }
        public double ToFoot(double var)
        {
            double foot = UnitUtils.ConvertToInternalUnits(var, DisplayUnitType.DUT_MILLIMETERS);
            return foot;
        }
    }
}

通过WPF创建窗口和revit交互创建标高

按钮:this.Close() 关闭

环境搭建:

删除App.xaml & App.config

引用revitAPI & revitAPIUI

复制本地:False

属性 输出类型:类库

然后再添加上button、textbox、label...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

周杰伦fans

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

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

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

打赏作者

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

抵扣说明:

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

余额充值