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

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

saikat
Autodesk Autodesk
21,211 Views
81 Replies
Message 1 of 82

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

saikat
Autodesk
Autodesk

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
21,212 Views
81 Replies
Replies (81)
Message 61 of 82

Anonymous
Not applicable

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:

firstplugin.jpg

 

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;
  }
}
0 Likes
Message 62 of 82

Anonymous
Not applicable

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

 

0 Likes
Message 63 of 82

MarryTookMyCoffe
Collaborator
Collaborator

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;

}

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 64 of 82

Anonymous
Not applicable

Every time I select an element, and then I select a point, I get the same error, doesn't matter the element I select.

0 Likes
Message 65 of 82

MarryTookMyCoffe
Collaborator
Collaborator

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

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 66 of 82

Anonymous
Not applicable

Hi Jboone,

 

         Thanks for sharing this link it was very much helpful.

0 Likes
Message 67 of 82

Anonymous
Not applicable

Thanks for sharing this query and solution.

0 Likes
Message 68 of 82

artistarulbabu
Participant
Participant

The link is not Working . Can u help me where can i find the wokring link?

 

Capture.PNG

0 Likes
Message 69 of 82

mikako_harada
Community Manager
Community Manager

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.) 

 

 


Mikako Harada
Developer Technical Services
0 Likes
Message 70 of 82

Anonymous
Not applicable

 

 


@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.) 

 

 


0 Likes
Message 71 of 82

naveen.kumar.t
Autodesk Support
Autodesk Support

Please refer the below link

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/my-fi...


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 72 of 82

GallowayUS_com_RonAllen1
Collaborator
Collaborator

Lesson 1 for Revit 2019 has no download link here:

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/simplecontent/content/lesso...

 

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.

Ron Allen
Galloway BIM
0 Likes
Message 73 of 82

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @GallowayUS_com_RonAllen1,

 

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

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 74 of 82

matthew_taylor
Advisor
Advisor

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).


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 75 of 82

GallowayUS_com_RonAllen1
Collaborator
Collaborator
Without the apps is there a way to test and debug?



Would be great if Autodesk had a read-only version of these applications but for hobby developers like myself it is difficult to justify the $1,600 to access ADN.


Ron Allen
Galloway BIM
0 Likes
Message 76 of 82

mikako_harada
Community Manager
Community Manager

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.  

 


Mikako Harada
Developer Technical Services
0 Likes
Message 77 of 82

GallowayUS_com_RonAllen1
Collaborator
Collaborator

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.

 

 

Ron Allen
Galloway BIM
0 Likes
Message 78 of 82

matthew_taylor
Advisor
Advisor
Can I suggest a different approach?
How about you ask your company if they'll waive the IP issue if you do it on your own time, and as a quid-pro-quo you give them x number of licences of the finished product for y years. In writing, of course.

That may give you enough traction to stump up the cash for ADN.

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 79 of 82

GallowayUS_com_RonAllen1
Collaborator
Collaborator

@matthew_taylor I wish : )

Ron Allen
Galloway BIM
0 Likes
Message 80 of 82

Anonymous
Not applicable

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.

0 Likes