Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check out the self-paced guide “My First Plug-in”

81 REPLIES 81
Reply
Message 1 of 82
saikat
17189 Views, 81 Replies

Check out the self-paced guide “My First Plug-in”

Check out the Self-Paced Guide “My First Plug-in” presented by the ADN Revit Team

http://www.autodesk.com/myfirstrevitplugin

 

Note on 5/11/2018:  My First Plug-in is being migrated to Knowledge Base (similar to this forum). Right now, the marketing URL is not working. In a mean time, you can access here:  
https://knowledge.autodesk.com/community/collection/my-first-autodesk-revit-plug

Still work in progress. Working on updating all the links, to the latest three releases, etc. 

 

Are you an Autodesk Revit power user with an interest in becoming even more productive? Would you like to automate or extend the capabilities of Revit, but are new to computer programming? If so, then this guide is designed for you.

 

“My First Plug-in” is a self-paced tutorial guide for a smooth introduction into the programming world. This is a “one-stop shop” learning path for users who know Autodesk products but are absolutely new to programming and are thinking about taking the plunge. In this guide, you will be working with the Autodesk Revit .NET API and the C# programming language. The supported product version is Autodesk Revit Architecture 2011 and succeeding versions.

 

There are many resources available on the web for you to learn about the Autodesk Revit API (Application Programming Interface), however, these resources tend to be designed for people who already know programming. This guide is different: it assumes no previous programming knowledge and yet helps you build your first plug-in quickly, without swamping you with details. You’ll have a working application within an hour of starting this material, irrespective of your current level of programming expertise.

 

The guide will start by reviewing the benefits of customizing Autodesk software before progressing onto lessons covering the use of the Autodesk Revit API. The lessons will start by building a working plug-in before covering more detailed explanations of the underlying principles and further developing the application’s functionality.

 

Product: Autodesk Revit 2011 or higher
Programming Language: C#
Application Programming Interface (API): Revit .NET API

If you have any feedback on this new guide let us know at myfirstplugin@autodesk.com

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Tags (2)
81 REPLIES 81
Message 2 of 82
jboone
in reply to: saikat

I hope you don't mind me posting here but I have a link I would like to share with the VB users out there who may be having a hard time with the C# part of code.  It will convert all code written in C# and covert it to VB or visa versa.  I haven't actually worked the code into anything usable, but it is very cool.

 

http://www.developerfusion.com/tools/convert/csharp-to-vb/

this one will convert a zip package

http://converter.telerik.com/

 

The only thing is it wouldn't create a package for you, you will have to do that on your own.  At least it may help some struggling programmers.

 

Message 3 of 82
gduncan74
in reply to: saikat

I get an error using "Reference". It looks like Autodesk changed the API for 2012. It's very frustrating that they use this for "My First Plug-in" and include apparently obsolete code.

Message 4 of 82
saikat
in reply to: gduncan74

Hi :

 

The My First Plug-in content was created using Revit 2011 APIs. But it shoudl still work with Revit 2012. If you want to work with Revit 2012, you can just remove the existing RevitAPI.dll and RevitAPIUI.dll from the References section in Visual Studio project and add new references to Revit 2012's Revit API.dll and RevitAPIUI.dll. The Visual Studio projects should build successfully with Revit 2012 API dlls too.

 

If I am misunderstanding your query here, can you please elaborate on what error you are receiving and how you are receiving it.

 

Lookign forward to hearing from you soon with more details,

cheers

Saikat



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 5 of 82
gduncan74
in reply to: saikat

This section of code:

 

//Define a Reference object to accept the pick result. 

Reference pickedRef = null;

 

produces a warning message:

 

Warning1'Autodesk.Revit.DB.Reference.Element' is obsolete: '"Property will be removed. Use Document.GetElement(Reference) instead"'

 

It still compiles OK, but it is frustrating to get warning messages while trying to learn how to use the API. Autodesk should update the guide for 2012. I spent a long time trying to figure out how to use Document.GetElement(Reference). 

Message 6 of 82
saikat
in reply to: gduncan74

Thanks for the clarification. Yes, this guide was created for Revit 2011 and some of the methods have been marked as obsolete in Revit 2012 API, though they continue to work with Revit 2012. I am working on how we can update the content for Revit 2012 (or add a note for using the new methods in Revit 2012 API).

 

In general, except for the one or two methods which have changed in Revit 2012 API, the guide which is aimed at providing an introduction to programming, getting started with Revit API, using the IDE, etc should still be useful in writing your first Revit plug-in and we hope you find it useful still.

 

Best regards

Saikat



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 7 of 82
channond
in reply to: saikat

I would like to know what the fix for this is in 2012, my plugin builds ok even though there is an error, but it doesn't seem to function correctly. I have searched the chm file, but with my limited programming experience, I cannot work out how to use the Document.GetElement(Refernce) instead of the Element reference.

Message 8 of 82
Joe.Ye
in reply to: channond

 

Hi Channond,

 

When compile the plug-in for Revit 2012, to dismiss the warning,

please replace this line
    Element elem = pickedRef.Element;

with the following line.
    Element elem = doc.GetElement(pickedRef);

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 9 of 82
channond
in reply to: Joe.Ye

Wow, that was pretty simple. Thanks for your prompt response. I tried about 6 different combinations to get this to work with no luck. I will now persever and try and make a few of my own plug ins.

Message 10 of 82
plawton5092
in reply to: saikat

Folks:

 

The second sentence in your statement

 

There are many resources available on the web for you to learn about the Autodesk Revit API (Application Programming Interface), however, these resources tend to be designed for people who already know programming. This guide is different: it assumes no previous programming knowledge and yet helps you build your first plug-in quickly, without swamping you with details.

 

…is, I am sorry to say, a gross mischaracterization.

 

The truth is that customization for Revit is completely inaccessible for any user who does not have at least a two-year degree in programming, and with that they would have also had to be a serious programming hobbyist for years prior.

 

If your actual goal is to show how difficult Revit is to program, and that we as users should therefore not ask for so many improvements in the program every release, (‘because it’s so hard to program!’), be assured that we can see right through that bovine manure – you wrote the thing to begin with, and you are professional programmers.  In sum, this demonstration does not constitute any sort of acceptable excuse for why autodesk almost never delivers what the paying customer base asks for, over and over and over again.

 

Why then, is that the case?

Message 11 of 82
itmanagement
in reply to: plawton5092

Just started to work through this. How do you get the Add-ins ribbon to appear?

Message 12 of 82
saikat
in reply to: itmanagement

Hi

 

When you create the add-in manifest file and place it in a location as mentioned in the 'Writing an AddIn Manifest' section in Lesson 1, you should be able to see the Addin Tab in the Revit UI and in that you should be able to see the Ribbon button.

 

Are you facing any particular problems with getting the ribbon to show up? Please ensure that the path mentioned in the Add-in Manifest file for the DLL is correct and accurately points to the location where the plug-in DLL has been created.

 

thanks

Saikat



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 13 of 82
ralvarez1976
in reply to: saikat

So realistically, how should one go about learning C# and the APi in order to make your own plugins? Is this really a two year investment in time?

 

I have customized AutoCAD and I am pretty good at Revit, and this is still greek to me. It seems like the intended audience for the API is the professional programmer.

 

Why have you guys decided to put the entry bar so high? Why not create a simple scripting language to control the UI and automate repetitive taks and create parametric models?

Message 14 of 82

I guess it would really depend on how you learn…how fast you learn… and most importantly how much time you can donate to learning. With a few hours a day, I would think within a couple weeks you should be writing basic programs within a programming language. Since you know Revit already then the learning curve should be lower when working with the API, however as I said there are all sorts of variables to consider when trying estimate the time it takes you to learn.

 

I won’t say that that the training guide is targeted at a professional programmer, I would it is targeted at a curious individuals, meaning if you have never programmed before, yes it will be Greek, but you have to use all the resources available in conjunction with this training, for example if you come across the word ‘variable’ and have no idea what it is, then it would be worth picking up a C# text book and understanding the concept more before continuing on in the guide to the next sentence.

 

We have chosen these languages because they are the most widely used languages and as a new programmer we want you to start off on the right foot.

 

Might I recommend these recorded videos here:

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975

 

Additionally, please feel free to email us at myfirstplugin@autodesk.com, and we can help you the areas you are challenged with, we would like to see your success if you are truly interested in learning the API,

 

Regards,

 

Kristine Middlemiss

Message 15 of 82
plawton5092
in reply to: itmanagement

"...it is targeted at a curious individuals, meaning if you have never programmed before, yes it will be Greek ..."

 

In essence, then you are agreeing with me that your own description:

 

This is a “one-stop shop” learning path for users who know Autodesk products but are absolutely new to programming and are thinking about taking the plunge.

 

is a gross mischaracterization ... as I said back in April.

 

You programmers are simply speaking a completely different language.  To the question "Do you know any code?",  you folks would answer "Yes: VB, C#, C++, Perl, Fortran, Java!", while we would answer "Yes: IBC, IMC, NFPA 13, NEC, AHSRAE 62, FM, UL!". 

 

Challenge:  Without any prior knowledge of architectural, structural, civil, or MEP design, you design a simple stand alone restaurant in New York City, using the codes I've listed above.  (Hint:  those are not going to be all the codes you'll need - but luckily for you, some of these exist on the internet:  http://www.iccsafe.org/Pages/default.aspx, http://www.nfpa.org/aboutthecodes/list_of_codes_and_standards.asp, http://database.ul.com/cgi-bin/XYV/template/LISEXT/1FRAME/fireressrch.html )  It'll be a 'self-paced guide to "My own Restaurant" - for folks who are absolutley new to designing and are thinking of taking the plunge.'  You are permitted the use of spare time only.

 

Good luck, I'll be interested to see your results in .... two years.

 

 

Message 16 of 82

I appreciate your response Kristine. Here is the problem I am having:

When I run the tutorials, and type the exact same code as you have it, copy / paste even it does not work. The sample code has errors in it. Also, I have taken a few online courses from Lynda.com on beginning programming, and beginning C#, and the examples are still hard to dissect. Part of the problem is that your tutorials are pretty basic, and the samples get much more complicated: i.e. they don’t build up gradually in complexity. The other problem is that most courses on C# don’t cover dealing with an API, but writing command console apps, which are much simpler. So this is what leads me and others to the conclusion that we need to be programmers in C# before we can even attempt to write an addin.

I understand that they are the most widely used languages, but by whom and for what purpose? I guess I am asking for a different set of functionality. I want to be able to create macros and scripts with a limited degree of flexibility, like AutoCAD's macro language. I would like to be able to make new command buttons that are collections of other commands, with some variables set. We should not need to go through C# in order to do this.

Your comment about "variables" is interesting. I know math and the concept of a variable is not new to me. The problem is that in these languages defining a variable is not achieved by writing "variable" but rather by writing "var" and sometimes some other syntax without the word “var” in it. That is not intuitive any way you cut it.

It’s as if these languages where written with the express intent of obfuscating information and creating job protection for programmers. As a society we lose when information is not free and overly complicated. We need better communication here so that we can accomplish more with the tool and get over Revit’s shortcomings.

 

Message 17 of 82
saikat
in reply to: itmanagement

Hi ralvarez1976

 

Sorry to hear about the errors you are facing when you copy the code in Visual Studio. Can you please share the details of the specific errors you see and I will be happy to look into them for you, and do my best to help resolve the errors for you. Each of the lessons too have downloadable VS projects and you might want to use those projects too, if you wish to - during your learning process through this Guide.

 

Revit exposes a .NET api which means we can use any of the .NET languages like VB.NET, C#, F# etc to be able to use the APIs and extend Revit's core functionality. It also provides a Macro environment called SharpDevelop but again the language that can be used to write code in has to be C# or VB.NET.

 

regards

Saikat

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 18 of 82
ralvarez1976
in reply to: saikat

From the "Revit 2012 API Developer Guide.pdf" document follow the instructions on pages 31 - 34. The code will have errors and not compile in the IDE.

Message 19 of 82
saikat
in reply to: itmanagement

Thanks for bringing this up. I was thinking there were some compilation errors with this 'My First Revit Plug-in' guide.

 

The errors you have mentioned in the pages 31-33 in the Revit API developer guide are known and I am working on including the missing information in the Developer Guide itself.

 

The two steps that are missing are:

1) Add the following namespaces in the initial part of the code itself:

using Autodesk.Revit.UI;

using Autodesk.Revit.DB;

using System.Windows.Media.Imaging;

 

2) Add a reference to the System.XAML. This can be done by right-clicking on the References tab in the Solution Explorer, Clicking on 'Add References'. A dialog will now show up and in this, click on the .NET tab and search for 'System.XAML' and select it and add it.

 

If there are someother missing pieces or obstacles in the Developer Guide, I would recommend we create a new thread on this topic in this API forum so that other users can easily locate this information - until we make the updates to the Developer's Guide.

 

Thank you for bringing this question up.

kind regards



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 20 of 82
zhangle
in reply to: saikat

i think what ralvarez1976 meant was the sample projects included in the SDK. i concur that the sample projects and the code / document are not written in a way that is friendly to non-programmers. especially when some programming techniques, like patterns, wrappers, win forms, etc. are involved. 

 

however, i do think this "1st plugin" series is written in a fairly novice-friendly manner, with plentty of explanations not only to the API but to basic programming concepts. although the claim of "no expeience" required is a little bit exaggerated. a dedicated learning of C# is required if you want to do something serious with the API. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community