revit二次开发之批量打开族文档,样板文件,项目文件

欢迎加入BIM行业开发交流1群 群号:711844216(满),二群群号:1016453207

1背景

小伙伴们在做revit二次开发的时候,可能需要通过程序去打开指定的族文档,样板文件,或者项目文件。

2思路

1.这三者其实都是一样的(参见代码中的注释1)
2.为了对打开的文档进行操作,必须将Document 设置为打开的文档(参见注释2)
3.如果对文档进行了修改,那么需要保存(参见注释3、4)
4.如果需要关闭这个打开的文档(参见注释5)

3程序

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace heiyedeqishi
{
    [Transaction(TransactionMode.Manual)]
    class Revit_API_Executable1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document document = uidoc.Document;
            //1文件地址,可以是rvt,rfa,rte
            string filePath = @"D:\黑夜的骑士\山海关大桥.rvt";
            //2这样,我们就能打开文档,并且获得这个文档的document
            Document doc = document.Application.OpenDocumentFile(filePath);
            try
            {
                //3接下来,把对整个doc的操作放到这儿就行了
                //....
                return Result.Succeeded;
                //4对文档进行保存
                doc.Save();
                //5关闭打开的这个文档
                doc.Close();
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}

4注意事项

需要Revit二次开发全流程教学 的朋友可以联系我qq:1056295111
拓展一下,我们通过不停的开打关闭文档,就可以实现批量操作了

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值