New Developer questions

New Developer questions

revitworkbench
Collaborator Collaborator
736 Views
3 Replies
Message 1 of 4

New Developer questions

revitworkbench
Collaborator
Collaborator

Hi, I am a Revit power user who wants to take a swing at developing his own addins. However the DIY tutorials cant help me even get off the ground. I downloaded Visual Studio Express (because I cant find Visual C# 2010 anywhere like it says to download.) The other one want me to open a new project, but right there it falls apart at the seems because his interface looks like (see picture) the one on the left, and mine looks like the one on the right....SigH...Can some one help me to get off the ground please? With maybe some help on how to actually START a program with how to find the SDK.exe file and the actual proper intallation of which code writing software to use, and how to hook everything up so that I can start to throw real API questions around?? Thanks!

0 Likes
Accepted solutions (1)
737 Views
3 Replies
Replies (3)
Message 2 of 4

augusto.goncalves
Alumni
Alumni
Accepted solution

The VS version you have is 2012, which will require some additional steps...

 

So if you don't have any other requirement to use 2012, consider use 2010

 

http://go.microsoft.com/?linkid=9709939 (installer link)

http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express (download page)

 

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 4

revitworkbench
Collaborator
Collaborator

Thank you! It wouldnt let me download 2010 from the webpage for some reason, what I really needed was that installer link. Now (hopefully), I will at least be able to follow all the help pages out there and at least get started in the right direction! Thanks a bunch!

0 Likes
Message 4 of 4

IAN~JAMES
Advocate
Advocate

Hi Michael,

 

I've been in the same boat for quite some time, trying to break the barriers to get into some proper api development, and I'm only just starting to make some ground, so happy to share what I have picked up.

 

Not sure why the party line seems to be to use VS 2010, I was using 2012 and am not using 2013, the same as a couple of other guys in our organisation who are doing some serious add-ins. So I think you are OK using VS2013 express... here's what I know you need to do to get an add-in building.

 

1. Add References

Right click on the project browser on the References section and go to "Add References" then browse to where Revit is installed and add two files

  • RevitAPI.dll
  • RecitAPIUI.dll

the next time you need to do this, VS should have remembered recent selection so you just need to tick them.

 

2. Import Autodesk Namespaces

At the top of the class file that you create when you create a new solution, you need to paste the following as a minimum. You may need to add additional namespaces as you get into more complex things, some Autodesk, and some .Net namespaces depending on what you are doing.

 

using Autodesk.Revit.Attributes;

using Autodesk.Revit;

using Autodesk.Revit.DB;

using Autodesk.Revit.UI;

 

3. Add the Transaction references (not sure if that is the right terminology?!) 

After the namespace you are creating but before the class definition, add the following two lines

 

[Transaction(TransactionMode.Automatic)]

[Regeneration(Regeneration.Manual)]

 

4. Change class so that it implements either IExternalCommand or IExternalApplication by adding to your class name

 

class Myclass : IExternalCommand

 

You can also right click on IExternalCommand in VS and select Implement Explicitely and it will create function stubs for you to fill in for all of the mandatory functions that you need to create. It usually puts in a NotImplemented exception in each so you have to replace them all with some meaningful code.

 

5. Add Post Build Events

I like to do this so that every time the project builds successfully, it automatically copies the resulting *.dll file and the *.addin manifest file to the correct locations. This is about as generic as I have managed to get it so that the same command will work with any build just copied and pasted in from one to another.

 

copy "$(ProjectDir)$(ProjectName).Addin" "$(AppData)\Autodesk\Revit\Addins\2015\$(ProjectName).Addin"

copy "$(SolutionDir)$(ProjectName)\$(OutDir)$(TargetFileName)" "C:\ProgramData\Autodesk\Revit\Addins\2015\$(TargetFileName)"

 

to add these... click on the "Project" menu at the top and it is the bottom option "YourProjectName Properties". Click on this and another tab opens in the editing space with a number of sections you can select using the menu down the left hand side. clcik on Build Events and past the above into the "Post-build event command line:" box at the bottom. Make sure that the drop down at the very bottom is set to "On successful build"

 

6. Create a *.Addin manifest file.

I usually create a blank file in notepad in the same folder as your source code files and then right click on the project browser and Add Existing Item so that I can edit it in the VS environement with everything else.

 

A really good resouce for GUID's is http://www.guidgenerator.com/ 

 

The following is copy pasted from my notes:

 

.Addin Manifest Files
See also: http://thebuildingcoder.typepad.com/blog/2010/04/addin-manifest-and-guidize.html

 

There needs to be a MyAddin.Addin File created and saved in the following location:

 

C:\ProgramData\Autodesk\Revit\Addins\2013

It should look something like this:

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<RevitAddIn>

  <AddIn Type="Command">

    <Text>Convert Pipes to Conduits</Text>

    <Description>Convert Pipes to Conduits</Description>

    <Assembly>C:\src\p2c\p2c\bin\Debug\p2c.dll</Assembly>

    <FullClassName>p2c.Command</FullClassName>

    <ClientId>835d6ad1-1a99-4039-95dc-e752ff635928</ClientId>

  </AddIn>

</RevitAddIn>

 

Add-In Manifest Tags

The basic and obligatory add-in manifest tags include:

  • <Assembly>: The full path to the add-in assembly file. Required for all ExternalCommands and ExternalApplications.
  • <FullClassName>: The full name of the class in the assembly file which implements IExternalCommand or IExternalApplication. Required for all ExternalCommands and ExternalApplications.
  • <ClientId>: A GUID which represents the id of this particular application. ClientIds must be unique for a given session of Revit. Autodesk recommends you generate a unique GUID for each registered application or command. Required for all ExternalCommands and ExternalApplications. The property UIApplication.ActiveAddInId provides programmatic access to this value, if required.
  • <Name>: The name of application. Required; for ExternalApplications only.
  • <Text>: The name of the button. Optional; use this tag for ExternalCommands only. The default is "External Tool".
  • <Description>: Short description of the command, will be used as the button tooltip. Optional; use this tag for ExternalCommands only. The default is a tooltip with just the command text.

It is possible to include more than one Addin definition in one manifest file too using the <RevitAddins></RevitAddins> tags to encapsulate multiple Addin definitions.

 

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<RevitAddins>

  <RevitAddIn>

    <AddIn Type="Command">

      <Text>Convert Pipes to Conduits</Text>

      <Description>Convert Pipes to Conduits</Description>

      <Assembly>C:\src\p2c\p2c\bin\Debug\p2c.dll</Assembly>

      <FullClassName>p2c.Command</FullClassName>

      <ClientId>835d6ad1-1a99-4039-95dc-e752ff635928</ClientId>

    </AddIn>

  </RevitAddIn>

  <RevitAddIn>

    <AddIn Type="Application">

      <Text>Convert Pipes to Conduits</Text>

      <Description>Convert Pipes to Conduits</Description>

      <Assembly>C:\src\p2c\p2c\bin\Debug\p2c.dll</Assembly>

      <FullClassName>p2c.Application</FullClassName>

      <ClientId>835d6ad1-1a99-4039-95dc-e752ff635928</ClientId>

    </AddIn>

  </RevitAddIn>

</RevitAddins>

 

7. Debugging.

 

It's been a while since I tried this but it did work really well... but I haven't really written up any notes on it yet, but here's the link to the articile explaining how to enable debugging. You basically build the project, then with VS still open you launch Revit and run the addin, and it respects any breakpoints you have set so that you can inspect variables, and step through the code.

 

http://through-the-interface.typepad.com/through_the_interface/2006/07/debugging_using.html

 

 

Good Luck... Hope some of the above was useful, I found it useful just writing some of it out again, and reading some of my notes back.

 

Warm Regards

0 Likes