Python or C#

Python or C#

Anonymous
Not applicable
8,839 Views
18 Replies
Message 1 of 19

Python or C#

Anonymous
Not applicable

Hi!

 

What languaje would you recommend me to start learning to program with Revit API? Is python fully functional by itself or does it needs pyRevit installed to work? Can you program independent Applications with Python?

 

Thanks!

 

0 Likes
8,840 Views
18 Replies
Replies (18)
Message 2 of 19

jeremytammik
Autodesk
Autodesk

> What language would you recommend me to start learning to program with Revit API?

 

Pick the one you like best. It must support .NET.

 

> Is Python fully functional by itself?

 

No, because it does not support .NET out of the box. Therefore, you need some kind of .NET support for it to interact with Revit API.

 

> Does it needs pyRevit installed to work?

 

No, not necessarily. That is one possible way to go. Another is the RevitPythonShell. Another is IronPython.

 

> Can you program independent Applications with Python?

 

Yes, by including the .NET support in one way or another. 

  

Anyway, what is 'independent'? 

  

Every Revit add-in needs Revit to execute.

  

Depending on how your code is packaged, you may need Revit-plus-something.

  

I do all my work in C#, because then I am completely independent of all the complexities mentioned above.

 

However, I also sometimes like the flexibility of a Python command line.

 

The RevitPythonShell gives me that when I really need to dig deeper interactively.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 19

Anonymous
Not applicable

Dear Jeremy,

 

Thanks so much for your fast reply, much appreciated.

 

By independently I referred that  the addin made by python can be installed and run in any computer with Revit and won't require any additional installations like pyRevit, as it works with C#, as you refer in Revit-plus-something.

 

Kind Regards.

0 Likes
Message 4 of 19

Sean_Page
Collaborator
Collaborator

I would second what Jeremy stated. I myself am exclusively C# when it comes to add-in or ZT nodes for Dynamo. I just prefer the ease of it just woeking, and the vast resources openly available for it. I would also say in terms of the Revit API, forcing yourself to use C# and explicitly define everything is a great way to learn, but may be a little slow at first because some things are a little more convoluted than they need to be.

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 5 of 19

stever66
Advisor
Advisor

I would also recommend C#, just because you will find the most examples in C#, and probably the most help from others if you use C#. 

 

I'm still a beginner at this programming stuff, but the comment about Python needing another program to work with .NET confuses me.   Both the Sharp Develop built in macro editor and Microsoft Visual Studio provide the options for either C# or Python.   I was under the impression that using either would basically create the same DLL file.

 

Am I completely misunderstanding, or maybe things have changed and Python no longer has the same limitations it once had?

 

 

 

0 Likes
Message 6 of 19

RPTHOMAS108
Mentor
Mentor

Also worth mentioning that Python can be used to extend Dynamo and that is interesting given the possibilities that Dynamo is now offering to those starting out their path to automation e.g. generative design, rapid generation of geometry, linking different programs etc. Although you can also develop custom nodes in Dynamo with C# but inherently Dynamo is extended with Python code blocks.

 

Having said that I would choose C# over Python since it is one of the languages explicitly written for .Net. IronPython is a .Net implementation of Python.

If you choose Python at an earlier stage in life then IronPython is how you would write a .Net application with it.

If you choose C at an earlier stage of life then C# would be your choice.

 

If you are only just making the choice you would choose either C# or VB.Net since they have the best IDE support in VS. Your Tab and BackSpace keys will also thank you, less work for them.

 

 

 

0 Likes
Message 7 of 19

jeremytammik
Autodesk
Autodesk

Some ruminations in response to Steve's question above:

 

Hmm. I am not aware of any possibility to reference .NET assemblies in Python in Visual Studio out of the box.

Yes, Revit's SharpDevelop built-in macro IDE includes support for Python. I believe that uses IronPython internally to hook up the Python code with .NET.

 

I looked at the overview of Python tools for Visual Studio and found a note saying, Visual Studio also supports IPython/Jupyter in the REPL, including inline plots, .NET, and Windows Presentation Foundation (WPF), but nothing else hinting at .NET support for Python in that environment.

 

Maybe Visual Studio can be combined with IronPython, as hinted at in the discussion on IronPython – Visual Studio 2010 or SharpDevelop?.

 

However, I also see this unanswered StackOverflow question on using Python for .NET for Python 3.4 in Visual Studio that seems to indicate it is not supported out of the box.

 

Actually, if you look directly at the IronPython site and its .NET integration documentation, it seems to be pretty straightforward in any context.

 

Does anyone have any reliable knowledge and experience on this to share?

 

Especially, is anyone using Python in Visual Studio to create stand-alone Revit add-ins?

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 19

floretti
Advocate
Advocate

I'm actually very interested in this conversation as well. I'm about to rollout a custom toolbar in Revit where all scripts are done in Python and the toolbar relies on the pyRevit interface to work. Our IT team unfortunately is not as welcoming of installing a free/open source tool such as pyRevit because of security, future updates and compatibility with our systems. As amazing as pyRevit is (thanks Ehsan), businesses have to consider the possibility that the development and updates of a free/open source tool could eventually stop in the future and I'm left wondering if I need to learn C# and start again from scratch independently from pyRevit.

 

This link is a great starting point for those who don't know much about creating a plugin natively in Revit but it would be great to have a simple(ish) link between python scripts and Revit API with toolbar creation capability (buttons, icons, etc), as opposed to something like Revit Python Shell.

0 Likes
Message 9 of 19

jeremy_tammik
Alumni
Alumni

The Revit API is a pure .NET environment.

 

The .NET framework supports complete transparent interactivity and compatibility between all .NET components.

 

As a result, you can, for instance:

 

  • Mix, mingle, connect, and simultaneously use any .NET class libraries, regardless of the programming language you implemented them in, e.g., C#, VB.NET, C++, F# (supported by Visual Studio out of the box), Ruby, Python, etc.
  • Automatically translate from any source programming language to any other target programming language simply by compiling to IL, intermediate .NET language, and decompiling into the other.

 

So, there is no reason to worry all too much, and there is not so big a learning hurdle if worst comes to worst.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 19

floretti
Advocate
Advocate

If you know of any tutorials on how to compile python code to IL please feel free to share. 😉

 

Thanks again, Jeremy.

0 Likes
Message 11 of 19

jeremy_tammik
Alumni
Alumni

No need for a tutorial. Paste your code into the Revit SharpDevelop IDE and click 'Translate'. That's all there is to it.

  

There may be more on other tools in here:

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 12 of 19

floretti
Advocate
Advocate
Thanks, Jeremy. That's helpful, have a great day! 🙂
0 Likes
Message 13 of 19

malcomjarr
Community Visitor
Community Visitor

When it comes to performance, C# and Python have different characteristics. C# is a statically typed language that is compiled into Intermediate Language (IL) and executed by the Common Language Runtime (CLR). The CLR provides features such as just-in-time (JIT) compilation, garbage collection, and runtime optimization, which can contribute to efficient execution and good performance. C# is often praised for its performance in areas such as Windows development, enterprise software, and game development.

 

 

Python, on the other hand, is an interpreted language that utilizes dynamic typing. It is generally considered to be slower than statically typed languages like C#. However, Python offers a vast ecosystem of libraries and frameworks that can enhance its performance for specific tasks. Libraries such as NumPy and pandas provide optimized data processing capabilities, while frameworks like TensorFlow and PyTorch are widely used for efficient machine learning and deep learning tasks.

 

 

Moreover, Python provides the option to optimize critical code sections by integrating native code through extensions or using libraries like Cython. By doing so, performance-critical parts of a Python program can be accelerated significantly. Additionally, Python's simplicity and ease of use often make it more productive for development, allowing developers to focus on solving problems rather than optimizing for performance.

Message 14 of 19

jeremy_tammik
Alumni
Alumni

Thank you for the analysis. I do not quite agree. Note that Python is used for the most extreme computationally heavy tasks, such as all the AI stuff going on right now. As you note yourself, all intensive computation can easily be implemented and compiled in C and C++ and easily linked in to Python. The same applies to C#, of course. So, whichever you choose, you can always optimise it to obtain the best of all worlds. Here is a speed comparison for a Factorial computation using different languages including .NET in which Python is the clear winner:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 15 of 19

mj_headrogen
Explorer
Explorer

Hi Elena
Moazam here.

I'm very good in python Programming but unfortunately my job is BIM Modelling as a Mechanical Engineer.
So i started to do some research on the topic of " Automation in Revit". I had same question in selecting Language, on Google, everyone talks about C# because there is no helping content on python, but i still believe that python is more stronger than other languages. And i wana stick with that. But alone , its very difficult for me to work , so i'm trying to make a team.
Can you please share your experience, how you started, and where did you reach?

May be, we can go together.
Thank you 

0 Likes
Message 16 of 19

Chuong.Ho
Advocate
Advocate

After go around 5 year, I can confirm that is let follow c# if you are working with Revit API, it is strong language, and you will like it, I used python 4 year ago but for now, Python just is language help me for process outside AEC with Machine Learning or Data Science.

Regard !

 

 

 

 

 

Chuong Ho

EESignature

Message 17 of 19

mj_headrogen
Explorer
Explorer
Hi chuong. H
Thanks for your reply.
But i don't know even the basics of C#😕.
What'd you suggest?
0 Likes
Message 18 of 19

Chuong.Ho
Advocate
Advocate

Just jump on and learning it, programmer need learning and update technology every day.

Chuong Ho

EESignature

Message 19 of 19

mj_headrogen
Explorer
Explorer
You are right.
Thanks
0 Likes