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
Hi, I'm trying the code of my first plugin in Revit 2018, but I get a runtime error.
May anybody help me?
Here's a screenshot of the error message:
Here's the code i've tried:
using System; using System.Collections.Generic; using System.Linq; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] public class Lab1PlaceGroup : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { //Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; //Define a Reference object to accept the pick result. Reference pickedRef = null; //Pick a group Selection sel = uiApp.ActiveUIDocument.Selection; pickedRef = sel.PickObject(ObjectType.Element, "Please select a group"); Element elem = doc.GetElement(pickedRef); Group group = elem as Group; //Pick a point XYZ point = sel.PickPoint("Please pick a point to place group"); //Place the group Transaction trans = new Transaction(doc); trans.Start("Lab"); doc.Create.PlaceGroup(point, group.GroupType); trans.Commit(); trans.Dispose(); return Result.Succeeded; } }
I found the error, the following line is wrong:
Group group = elem as Group;
The compiler don't let me cast an Element type to a Group type, so the variable group is assigned with the null value. I've tried an explicit cast, but still doesn't works. How may I fix it?
Thank you
or Element is not a Group Type, it is posible that you select wall or some other element
make
if(elem.Type() == typeof(Group))
{
group = elem as Group;
}
else
{
Result.Failed;
}
Every time I select an element, and then I select a point, I get the same error, doesn't matter the element I select.
as I said you don't select Group
use :
https://boostyourbim.wordpress.com/2017/04/28/revit-lookup-2018-install/
this way you will be able to see what type elements are in Revit
Hi Jboone,
Thanks for sharing this link it was very much helpful.
The link is not Working . Can u help me where can i find the wokring link?
The site is being migrated to Knowledge Network (similar to forum). Looks like old one is no longer there before we finish migration 😞 Sorry about it.
In the mean time, you can access the new site here:
https://knowledge.autodesk.com/community/collection/my-first-autodesk-revit-plug
To Do for our side:
The link to the very first lesson in the series is broken, preventing me from even beginning the tutorial.
Can this be fixed? When i click it from the main page it says page not found, so I went to the authors page and found his Lesson 1a and when i opened that, I got access denied.
@mikako_harada wrote:The site is being migrated to Knowledge Network (similar to forum). Looks like old one is no longer there before we finish migration 😞 Sorry about it.
In the mean time, you can access the new site here:
https://knowledge.autodesk.com/community/collection/my-first-autodesk-revit-plug
To Do for our side:
- update marketing url to point to this new site.
- update to the latest 3 releases (Revit 2017/8/9).
- check all the links and make sure it point to the correct one. (e.g., I see the lesson summary page point to wrong page.)
Please refer the below link
Lesson 1 for Revit 2019 has no download link here:
And how do I get a copy of Revit to work on API at home, on my own personal computer for more than 30 days? Is the educational license an acceptable viable option if we are learning the Revit API and creating small plugins here and there?
I have visual all ready to go but obviously need the 2019 DLLs and application for testing and debugging.
Hi @WM_Ron_Allen,
Apologies for the inconvenience.
We have updated the link lesson 1_revit_2019_projects.zip (327 KB) in Lesson 1
Could you please try to download the files again? Please let us know if you are unable to download the files
Hi Ron,
One of the cheapest ways to get most Autodesk software installed for development (non-production) purposes is to join the ADN (Autodesk Developer Network).
Alternatively, you could use Nuget packages (these will provide the API dll files) so you can at least write the code at home (for zero cost).
Hi Ron,
If you use Revit at work, you may be able to borrow license. (You may need to talk with your manager and asking what you are planning to do - self-education).
For the detail of license with, you may want to post to licensing forum:
https://forums.autodesk.com/t5/installation-licensing/bd-p/24
(I'm not an expert of licensing, and there are many variations now...)
You cannot test your app without Revit.
Appreciated-
lol- yeah having a Revit to work with is the catch : ) I have a programming background- just diggin' in on Revit.
There is an ownership issue there I must avoid- anything on company hardware or software is company IP.
Having worked in Revit for 12+years now I know the potential of these especially the ones I am thinking about- getting started is the difficult part ; ) But once I do hopefully it will be self sustaining.
In this "My First Plug-in" guide, we required Visual Studio. But as I am using Revit 2019 and I don't have access to Visual Studio(not used in my Company yet), But Revit 2019 have Sharpdevelop and Macros Manager, I want to write my first plug-in in Sharpdevelop using C# or Python. Both language would work, I need refrence to start with sharpdevelop with the same program.