Running C# plugin in Pyrevit

Running C# plugin in Pyrevit

Running C# plugin in Pyrevit

Updates

Updates

Updates

×

×

×

May 25, 2024

May 25, 2024

May 25, 2024

Introduction

The worlds of software development and architectural design often work with different programming languages and tools. However, sometimes there are creative ways to bring these worlds together. In this article, we will explore how it is possible to run a plugin written in C# inside PyRevit, a Python-based tool.

What is PyRevit?

PyRevit is a powerful tool that enables creating and running Python-based plugins in Revit. The flexibility of Revit and the efficiency of Python combine to speed up and automate the architectural design process.

Integrating a C# Plugin into PyRevit

To run a plugin written in C# in PyRevit, certain steps must be followed. By taking these steps step by step, we will explain the process of integrating a C# plugin into a PyRevit button.

Step 1: Preparing the C# Plugin Step 2: Creating a Python Based Interface Step 3: Bridging the Two Languages

A Sample Project

In this section, we will show how to run a C# plugin in PyRevit through a sample project. The project will include a Revit plugin written in C# to automate a specific task, which will be integrated into the PyRevit interface and triggered with Python.

Invoke buttons can call an external command (implementing IExternalCommand) from another dll. However, they run the external command without loading the assembly in Revit context so the dll file can be modified while Revit is running. They are a great method to incorporate your high-performance C# dlls into your pyRevit extensions. Invoke Buttons, need the parameters below defined in the bundles' metadata file. See Bundle Metadata for more information on these files.

extension: .invokebutton
# include the key:values below in the bundle metadata file

assembly: RevitWeb.dll     # full path to dll. if the dll is included in the bundle lib/
                           # or the parent bundle lib/ directory just enter the full dll name
                           # pyRevit will find the dll in the parent lib/ directories

command_class: Command     # name of the external command class

Invoke Buttons are also smart about the assembly types implementing the IExternalCommand interface. So if there is only one external command inside your dll assembly that implements the IExternalCommand interface, you can skip defining the command_class in the bundle metadata file. pyRevit will automatically find the correct type and will run the Execute method on it.

title: Test Direct Class Invoke (Custom Title)
tooltip: Test Direct Class Invoke Tooltip
author: "{{author}}"
highlight: new
context: zero-doc
assembly: PyRevitTestBundles
command_class

Summary of Steps and Conclusions

In this part of the article, we will summarize the steps and discuss the potential advantages and challenges of combining PyRevit with C# plugins. We will also evaluate how this approach can contribute to architectural design processes.

Conclusion

Running C# plugins in PyRevit is an exciting step forward in merging the worlds of software development and architectural design. By following the steps we discussed in this article, you can implement this integration in your own projects and further optimize your design processes.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

See Also

See Also

See Also

See Also