A toolkit for simplifying your Revit plugin development.
-
Install Revit Templates.
-
Add this as a submodule to your project:
git submodule add https://github.com/ArchiDog1998/SimpleRevit
-
Add it to your plugin's CSProj file:
<ItemGroup> <ProjectReference Include="..\SimpleRevit\SimpleRevit\SimpleRevit.csproj"/> </ItemGroup>
Here is an example of this repo.
All these commands are inherited from ExternalCommand. So for further usage, please check this wiki.
CmdBase contains some definitions of Revit.Async. If you want to use it, please set UseRevitAsync
to true.
using Autodesk.Revit.Attributes;
using SimpleRevit;
[Cmd(Name = "Easy One")]
[Cmd(Panel = "Commands")]
[Transaction(TransactionMode.Manual)]
public class CommandEasy : CmdBase
{
protected override bool UseRevitAsync => false;
public override void ExecuteMain()
{
}
}
If your UseRevitAsync
is true, please make all your writing stuff to RevitTask.RunAsync
.
CmdBaseMvvm is an mvvm-ready command class. The View it created will not be irresponsible while the command is running. Please don't forget to define your view and your view model.
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Serilog;
using SimpleRevit;
using Tests.ViewModels;
using Tests.Views;
[Cmd(Name = "Normal One")]
[Cmd(Image = "Resources/Icons/RibbonIcon16.png")]
[Cmd(LargeImage = "Resources/Icons/RibbonIcon32.png")]
[Cmd(Panel = "Commands")]
[Transaction(TransactionMode.Manual)]
public class CommandNormal : CmdBaseMvvm<TestsView, TestsViewModel>
{
protected override bool UseRevitAsync => false;
public override void ExecuteMain()
{
using var trans = new Transaction(Document);
trans.Start("Test");
foreach (var wall in Document.GetInstances(BuiltInCategory.OST_Walls))
{
var param = wall.GetParameter(BuiltInParameter.WALL_BASE_OFFSET);
param.Set(0.2);
UpdatePercent(100);
Task.Delay(1000).Wait();
Log.Debug("Succeed!");
}
trans.Commit();
}
}
All these commands are inherited from ExternalApplication. So for further usage, please check this wiki.
Almost everything is down here, don't forget to create one application that is inherited from this.
There are two attributes for you to create the ribbon ui easily.
The Cmd
attribute is designed for ui showing in the ribbon panel. And the Priority
attribute is designed for changing the order of the loading button in the ribbon panel.
There are also some extensions for parameter writing and creating. Try them by yourself!