做好了插件,后面一步就需要把插件加载到面板上了。
这里revit专门为加载插件提供了一系列api。具体api的介绍看revit二次开发官方教程第10章。但这里讲得很泛,缺少完整代码的实际例子。另外有个难点(textbox),我现在也没搞清楚,还请后面研究这一块的人加以补充。
好吧,直接粗暴的放源代码吧。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace MenuTool
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
string macString = GetMacAddress.GetMacAddressByDos();
if (macString == "FC:AA:14:42:B5:79" || macString == "1C:1B:0D:37:58:75" || macString == "48:8A:D2:35:95:53" || macString == "48:8A:D2:35:BF:BB" || macString == "48:8A:D2:35:D2:D2" || macString == "48:8A:D2:35:95:50"|| macString == "48:8A:D2:35:47:4C")
{
//添加一个模型线转钢筋的新面板
RibbonPanel ribbonPanel1 = application.CreateRibbonPanel("模型线转钢筋");
//在面板上添加钢筋按钮
RibbonItemData item1 = new PushButtonData("批量建纵筋", "纵筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线转钢筋批量建纵筋.dll", "批量建纵筋.Class1");
RibbonItemData item2 = new PushButtonData("快速建箍筋", "箍筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线转钢筋快速建箍筋.dll", "快速建箍筋.Class1");
RibbonItemData item3 = new PushButtonData("批量建任意钢筋", "任意钢筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线转钢筋批量建任意钢筋.dll", "批量建任意钢筋.Class1");
IList<RibbonItem> listRibbon1 = ribbonPanel1.AddStackedItems(item1, item2, item3);
//添加一个模型线族转钢筋的新面板
RibbonPanel ribbonPanel2 = application.CreateRibbonPanel("模型线族转钢筋");
//在面板上添加钢筋按钮
RibbonItemData item4 = new PushButtonData("模型线族转纵筋", "纵筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线族转钢筋模型线族转纵筋.dll", "模型线族转纵筋.Class1");
RibbonItemData item5 = new PushButtonData("模型线族转箍筋", "箍筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线族转钢筋模型线族转箍筋.dll", "模型线族转箍筋.Class1");
RibbonItemData item6 = new PushButtonData("模型线族转任意钢筋", "任意钢筋", @"C:ProgramDataAutodeskRevitAddins2015钢筋插件模型线族转钢筋模型线族转任意钢筋.dll", "模型线族转任意钢筋.Class1");
IList<RibbonItem> listRibbon2 = ribbonPanel2.AddStackedItems(item4, item5, item6);
//将菜单转化为按钮
PushButton pushButton1 = listRibbon1[0] as PushButton;
PushButton pushButton2 = listRibbon1[1] as PushButton;
PushButton pushButton3 = listRibbon1[2] as PushButton;
PushButton pushButton4 = listRibbon2[0] as PushButton;
PushButton pushButton5 = listRibbon2[1] as PushButton;
PushButton pushButton6 = listRibbon2[2] as PushButton;
return Result.Succeeded;
}
else
{
TaskDialog.Show("Revit","您的机器不在允许使用范围以内,请联系作者:广州阿仁 13202088954");
return Result.Cancelled;
}
}
}
}
最后的效果如上图。
微信公众号:xuebim
关注建筑行业BIM发展、研究建筑新技术,汇集建筑前沿信息!
← 微信扫一扫,关注我们+
评论前必须登录!
注册