Revit二次开发--外部application添加到附加模块注意的一些点

新手上路。自己摸索的。

一个是,代码先编好(网上很多,command的或者application的,简单的就实现那一两个接口就行),生成dll。
然后在revit的插件管理器(Add-In Manager)里面load进来,去你的dll文件夹load。然后右下角有个save,是生成对应.addin文件的。别自己手打.addin文件。可以选择生成在dll的当前文件夹,也可以直接生成在revit启动加载那个文件夹。路径、guid什么的都是自动生成的,改都不用改。
如下图:
在这里插入图片描述

我的生成在这:
在这里插入图片描述
复制到2016的文件夹:
在这里插入图片描述

!!为什么要复制?因为我的revit是2016,插件管理器是2014的。自动生成的.addin放在了2014的文件夹里面,然后revit是在2016的文件夹里面加载插件。我的问题就是这里,老加载不进去。。。复制过去就行了。另外.addin文件命名是随意的,里面的配置才是有用的。但是我们都知道,好的命名有利于交接和管理等。
在这里插入图片描述
在这里插入图片描述

最后效果截图:
在这里插入图片描述

(另外,一开始我是自己照书上手打.addin文件的,然后拷到2016文件夹里面,一直加载不出来,偶尔还会让revit卡死。。。然后还碰到load失败的,一上午没搞定。然后下午重启电脑,摸摸索索,终于搞定了,总结出上面两点教训。但是上午为什么load失败还是没有头绪。)
(当时是一个解决方案里面放了两个项目。一个是command的,一个是application的。command那个可以load,运行没问题。application那个load失败,把自己写的.addin拷到2016里面,也加载不出来。不知道哪里冲突了还是怎样。那个.addin应该是没问题的?或者也有问题。反正现在知道.addin是生成的,找到正确方法就好了。)–8月吐槽:莫名其妙。复现不了。告辞。

–8月更新–
在revitlookup里面找了点借鉴的代码放上来:

//其他using
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;  
namespace MyTools
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Apps : IExternalApplication
    {
        static string ExecutingAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            Autodesk.Revit.UI.RibbonPanel rvtRibbonPanel = application.CreateRibbonPanel("SmallTools");
            PulldownButtonData data = new PulldownButtonData("Options", "SmallTools");

            RibbonItem item = rvtRibbonPanel.AddItem(data);
            PulldownButton optionsBtn = item as PulldownButton;

            optionsBtn.AddPushButton(new PushButtonData("SelectAll", "SelectAll", ExecutingAssemblyPath, "MyTools.SelectAll"));

            return Result.Succeeded;
        }
    }

    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class SelectAll : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;
            Selection sele = commandData.Application.ActiveUIDocument.Selection;
            //to do
            
            return Result.Succeeded;
        }
    }
}

效果如下图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值