Develop Autodesk Inventor Addin using C# – Part 2

Part 2a:

Watch High Resolution video of Part2a videos on AR-CAD


Part 2b:

 

Watch High Resolution video of Part2b videos on AR-CAD


Part 2c:

 

Watch High Resolution video of Part2c videos on AR-CAD


This video tutorial is in continuation of my earlier post on Developing Autodesk Inventor Addin using C# – part 1. In this session, we go a step further and create Command Button(s), that is added into a Custom Command Bar, which in turn gets added into Panel Bar of Assembly Files.

 

We start with a project that gets formed when we use Inventor Addins Template for C# language. We then add a couple of references and use most of the code from SimpleAddin that gets shipped along with Inventor in its SDK kit. We use the Button class from SimpleAddin as it is, and then append code to StandardAddInServer.cs file as explained in the video.

Some of the main points discussed in the video are as follows:

  1. How to deal with User Interface Event
  2. How to deal with Event Handler for Command Bars and Environments on Reset
  3. How to use ‘try & catch’ loop to handle errors effectively
  4. How to extend Button base class. Each ButtonCommand (AssemblyTreeButton) will have a Class which implements Button class
  5. How to load Image icons (.ico) for User Interface items
  6. How to create Buttons (CommandButtons)
  7. How to create Command Category
  8. How to add Button to Command Category
  9. How to create a custom command bar (toolbar), only the first time the addin loads up
  10. How to add a custom command bar to an available Environment (again only first time)
  11. How to Restore CommandBars and Environments and clean up the custom CommandBars and Environment changes done by activate method
  12. How to run a command when a button is clicked
  13. How to Build a Solution from Visual Studio 2005
  14. How to register and unregister an Addin using RegAsm.exe (easier way)
  15. How to check whether you addin has been loaded in the Inventor when it is started

I hope a lot of basics of a Command Button are covered in this video tutorial. In the coming ones, I would try to work on “Debugging an Addin from Visual Studio” and more complex addins which actually do something other than just showing some messages.

Please comment below if there is anything that is not clear. To view high resolution Videos of the above screencasts, check them out at AR-CAD at part2a, part2b, part2c.

Update: Looks like the install.bat and uninstall.bat files content are not very clear in the video, here are they in text

Install.bat

@echo off

C:WINDOWSMicrosoft.NETFrameworkv2.0.50727RegAsm.exe /codebase AR-CADInventorAddIn4.dll

PAUSE

Uninstall.bat

@echo off

C:WINDOWSMicrosoft.NETFrameworkv2.0.50727RegAsm.exe /unregister AR-CADInventorAddIn4.dll

PAUSE

Customize Autodesk Inventor API using C# – Part 2


Watch High Resolution video on AR-CAD

I hope you have gone through my previous posts on Inventor API a) Introduction to Autodesk Inventor API and Customization and b) Customize Autodesk Inventor using C#. It is also assumed that you have gone through DevTV: Introduction to Inventor Programming Video, which is on Inventor Customization page. In the above video, we connect to Inventor API from Visual C# (Visual Studio 2005). I have just replaced the VB.NET code that was used in DevTV tutorial with the corresponding C# code. You can see the comparison below. Please note how GetObject in VB.NET is replaced by a much more lengthier code. If the above youtube video is not very clear, watch it on AR-CAD.

VB.NET Code
[sourcecode language=’vb’]
Dim oApp As Inventor.Application
oApp = GetObject( , “Inventor.Application”)
MsgBox(“Number of open docs = ” & oApp.Documents.Count)
[/sourcecode]

Visual C# Code
[sourcecode language=’c#’]
Inventor.Application oApp;
//The below initialization is on a single line
oApp =
(Inventor.Application)System.Runtime.InteropServices.Marshall.
GetActiveObject(“Inventor.Application”);

int number_int = oApp.Documents.Count;
string number_string = Convert.ToString(number_int);

MessageBox.Show (“Number of open docs =” + number_string);
[/sourcecode]

Customize Autodesk Inventor API using C#

In continuation of previous post on Introduction to Inventor API and Customization, this blog post will show some insights on how to customize Inventor API using Visual C# and Visual Studio 2005.

It is assumed that you have installed Autodesk Inventor (Version 10 or above) and Visual Studio 2005. As per the discussion over Inventor Customization forum, it is suggested that you have Visual Studio 2003 or 2005 for the Inventor Addin Template to work properly. At present, Addin Template does not get installed in Visual Studio 2008.

To get started with Visual C# and Visual Studio IDE (Integrated Development Environment), watch the following Videos from MSDN Library.

  1. Introduction to Visual C# 2008 Express Edition. Though we would be using Visual Studio 2005 for our development purpose, Visual C# Express Edition has similar functionality as Visual Studio. In this video, basic understanding of how an IDE works could be gained and also how C# programs and projects are developed and built.
  2. Introduction to C# Programming Language. This video shows how to develop C# applications using Visual Studio 2005. It is highly recommended that you download this package installer and upon installation on your system, you have a copy of Video downloaded and also a MS Word Document which is basically a transcript for the Video and also explains Basics of C# in a very good way.

I hope you also have downloaded DevTv: Introduction to Inventor Programming from Inventor Customization Page. In this video, Mr. Wayne Brill of Autodesk has explained API concepts very well, but they are either in VB6 or VB.NET. I would like to highlight to the audience that even in Inventor Programmers Help (Located in Help tab), most of the code examples are given in VB.NET or VBA.

I would try to bridge the gap by giving out equivalent C# code in the blog posts to follow. You may also be interested to check out a free VB.Net to VC# translator I stumbled upon, though I haven’t used it yet.

Introduction to Autodesk Inventor API and Customization

Update: IN-Motion, a Motion and Dynamic Simulation Addin for Autodesk Inventor has been launched by us.

Update: Video tutorials on usage of IN-Motion for Dynamic Simulation of Autodesk Inventor Assemblies.

Autodesk Inventor Logo For those in CAD (Computer Aided Design) field, Autodesk would have been a very common company they would have come across. One of the most famous CAD software, AutoCAD belongs to their stable. Autodesk Inventor is somewhat an extension of AutoCAD, specific for Manufacturing section and deals mainly with 3D CAD, solid modeling of parts and then building assemblies out of them, Rapid Prototyping and many more advanced features. Inventor has been a great success in this field and it is evident from the fact that there are more than 800,000 official licensed users of Inventor across the world.

One of the strong points for the success is the fact that Autodesk has opened its API (Application Program Interface) to developers who can extend the base product to fit into their requirements. This is called Customization of the CAD package. Inventor also has its API exposed to developers through COM (Component Object Model) interface using which developers can customize the base installation of Inventor to tailor made needs such as automating a certain process or developing addins/ addons/ plugins which do specific task.

For those, who want to get started with Inventor API customization using their SDK (Software Development Kit), the following steps can be followed.

  1. Introduction to Inventor API and VBA (Visual Basic for Applications). The attached document is from Autodesk University of 2003. Though it may seem to be old, its a very good starting point and the code works even in latest versions of Inventor.
  2. You may also consider going through the 3 part series of Focused VBA for Inventor, which is a part of AUGI Training Program (2007) : Part 1, Part 2 and Part 3.
  3. Visit Inventor Customization page and get more insight, by watching 1 hour video on Basics of Inventor API and developing addins for Inventor (DevTV: Introduction to Inventor Programming )
  4. Decide upon which .NET technology you would be comfortable in developing Addins and Standalone applications (Either of VB.NET, VC++ or Visual C#)
  5. Browse through Inventor Customization forum to get more insights, code examples and also problems faced by other developers and also an active Autodesk support team which answers those queries
  6. If you happen to progress well, consider joining Autodesk Developers Network (ADN) and also attend AUGI Training Programs (ATP)
  7. Also you can keep a track on my Blog as I would be trying to pen down my learning, developing full fledged Addins for Inventor and also other major CAD software.