Ribbon菜单的空间有限,因此可能需要大量控件放在一个Windows窗体里,
然后在窗体里执行Revit命令。方法就是传递参数,新建IExternalCommand
调用Execute();
窗体
命令
有些初接触的朋友可能因为一点问题就进行不下去了,建议我把代码发全并附全部源码。
我新建了一个RevitBlog项目,用来记录平时的小积累。
本文源码下载: http://revit.5d6d.com/thread-1072-1-1.html
把RevitAPI.dll和RevitAPIUI.dll添加引用。
这两个dll在revit的安装目录中。
然后在窗体里执行Revit命令。方法就是传递参数,新建IExternalCommand
调用Execute();

窗体
using
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DB = Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitBlog
{
public partial class FrmCmd : Form
{
ExternalCommandData cmdDataForm;
string msgForm;
DB.ElementSet elementsForm = new DB.ElementSet();
public FrmCmd()
{
InitializeComponent();
}
// 重载一个构造函数,用来传递参数
public FrmCmd(ExternalCommandData cmdData, string msg, DB.ElementSet elements)
{
InitializeComponent();
cmdDataForm = cmdData;
msgForm = msg;
elementsForm = elements;
}
private void btnCmd_Click( object sender, EventArgs e)
{
cmdFromForm fromForm = new cmdFromForm();
fromForm.Execute(cmdDataForm, ref msgForm, elementsForm);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DB = Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitBlog
{
public partial class FrmCmd : Form
{
ExternalCommandData cmdDataForm;
string msgForm;
DB.ElementSet elementsForm = new DB.ElementSet();
public FrmCmd()
{
InitializeComponent();
}
// 重载一个构造函数,用来传递参数
public FrmCmd(ExternalCommandData cmdData, string msg, DB.ElementSet elements)
{
InitializeComponent();
cmdDataForm = cmdData;
msgForm = msg;
elementsForm = elements;
}
private void btnCmd_Click( object sender, EventArgs e)
{
cmdFromForm fromForm = new cmdFromForm();
fromForm.Execute(cmdDataForm, ref msgForm, elementsForm);
}
}
}
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
namespace RevitBlog
{
// 显示一个非模态窗体
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdShowForm : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
FrmCmd frmCmd = new FrmCmd(cmdData, msg, elements);
frmCmd.Show();
return Result.Succeeded;
}
}
// 在窗体里执行Revit命令
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdFromForm : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
string version = cmdData.Application.Application.VersionBuild;
version += " \n " + cmdData.Application.Application.VersionName;
version += " \n " + cmdData.Application.Application.VersionNumber;
TaskDialog.Show( " info " , version);
return Result.Succeeded;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
namespace RevitBlog
{
// 显示一个非模态窗体
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdShowForm : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
FrmCmd frmCmd = new FrmCmd(cmdData, msg, elements);
frmCmd.Show();
return Result.Succeeded;
}
}
// 在窗体里执行Revit命令
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdFromForm : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
string version = cmdData.Application.Application.VersionBuild;
version += " \n " + cmdData.Application.Application.VersionName;
version += " \n " + cmdData.Application.Application.VersionNumber;
TaskDialog.Show( " info " , version);
return Result.Succeeded;
}
}
}
我新建了一个RevitBlog项目,用来记录平时的小积累。
本文源码下载: http://revit.5d6d.com/thread-1072-1-1.html
把RevitAPI.dll和RevitAPIUI.dll添加引用。
这两个dll在revit的安装目录中。