How to learn scripting for both Autocad and Revit ?

How to learn scripting for both Autocad and Revit ?

Angayo
Advocate Advocate
1,787 Views
3 Replies
Message 1 of 4

How to learn scripting for both Autocad and Revit ?

Angayo
Advocate
Advocate

Dear forum members,

 

First, I wan to clarify that I don’t care about scripts per se. I care about doing non-standard stuff that probably requires programming. However, I don’t know what charges terms like API, macro’s and scripts cover, so I’ll use script to refer to my interest.

 

I asked in the Autocad Customization forum how I should get into Autocad scripting if I want to be able to reuse my work as much as possible for Revit. I was told there are no similarities between AC Achitecture and Revit. Is that true ?

 

I suspect that if I write a script for Autocad, I won’t be able to recycle it for Revit, but I was hoping that some acquired skills would be reusable, specifically a programming language that can be used for scripting in both. I can’t find an exhaustive list of programming languages for those programs. Does anyone know what languages if are common for both ? I have the impression C# works for both, but I only learned C and C++ a long time ago. VBA would be most convenient, as I can use that for Excel as well.

0 Likes
1,788 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Is that true ?

 

Yes, totally.

 

Yes, C# would work fine for both the Revit API and the AutoCAD.NET API.

 

Here is an overview of AutoCAD and Revit SDKs:

 

http://thebuildingcoder.typepad.com/blog/2018/01/areaload-force-direction-cmake-sdk-access.html#3

 

For Revit, read the getting started material before doing anything else:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Best regards,

 

Jeremy



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

Message 3 of 4

RPTHOMAS108
Mentor
Mentor

I would avoid VBA because it is not at all like VB.net. but is similar enough to be confusing. Every time I use it in Excel it teaches me bad habits like:

 

Public Function HereIsAFunction()

HereIsAFunction = 1

End Function

 

C# is the language you'll find most examples of.

 

The secret to reusable code is to limit your interaction with the interface (be it AutoCAD API/Revit API) to discreet points that can be quickly replaced. e.g. I'm grateful for helper objects such as Transform but if I use it in a class I know that file will be forever tied to the Revit API. If however I mirror the functionality of the object then I can convert my object into the required API object when it is required (at a point of interaction with the API). It's not always easy because those API guys create a lot of helpful sophisticated objects that I wouldn't even begin to understand how to replicate.

 

The main point is you can keep a barrier of separation and create specific class files that you know are where the linkages with the API occur. Other files have your non API specific objects that you can use anywhere. At the moment I'm solely developing for the Revit API so have got a bit lazy regarding the separation noted above. Such separation is also required for serialisation, apart from the most basic objects your won't be able to serialise API objects (I believe). 

Message 4 of 4

Angayo
Advocate
Advocate

So, if I expect I will need to do scripting for Revit later on, I should not try recycling my VBA efforts with Excel by using VBA for Autocad, but learn C# in stead.

 

 

Does anyone happen to have advice on how to learn C#, given that I can already program in  general and have learned (and forgotten) C en C++ ?

0 Likes