Design Patterns applied to the Inventor API

By Philippe Leefsma

Here is the complete content of one of my AU 2012 class dealing about design patterns and let’s say tips & tricks or good practices when it comes to developing Inventor add-ins.

Developing add-ins in general, but especially Inventor ones since it is our focus here, has this in common that you will need most of the time to create a new project and setup the plumbing for couple of common things: typically the .addin file registration steps, including copying that file to the correct location for debug testing; if you have written add-ins previously, you will also most likely want to reuse a few utility functions that handle basic task about the operating system, picture conversion and more depending on what your add-in is doing; in case your add-in provides new functionality, you want it to create at least one command so the end user can access it through the Inventor graphical interface. For that you need to create new elements through the Ribbon bar and potentially implement user interaction mechanism if your command is going to prompt the user for any kind of selection.

In this class I tried to gather the most useful knowledge I acquired over the past few years where I have been supporting developers about Inventor API related questions, writing several add-ins myself and also collecting interesting ideas and techniques collected among my colleagues at Autodesk.

The purpose of this document is to expose some common tasks, reusable code samples and also propose an implementation of a few design patterns, directly applied to the Inventor API and specific to add-in creation.

To maximize reusability and efficiency of this content, I wrapped it all up inside a Visual Studio project template and associated item templates. With a slight experience of Inventor add-in programming, a developer should be able, through the use of those templates, to generate from scratch a fully functional Inventor command with less than five minutes of work!


Comments

8 responses to “Design Patterns applied to the Inventor API”

  1. Aditya Joshi Avatar
    Aditya Joshi

    Hello Philippe,
    I trying to create a small c++ addin for Inventor 2014, for demonstrating a issue which we are facing while accessing PartComponentDefinition->Parameters->Count.
    I used the Inventor 2014 SDK wizard for creating the Sample Addin Project.
    The *.manifest file has been copied to the Inventor Addin location in Program Data, the *.dll has been copied to the Inventor2014\Bin folder.
    Issue: I able to see the Addin in the Add-In Manager, that is the *.manifest file seems to be working pretty fine. but the Addin appear unloaded.
    Can you please suggest anything I might have missed.
    Regards,
    Aditya

  2. Philippe Avatar
    Philippe

    Hi Aditya,
    Your question seems to be unrelated to the topic of that post… In the future please log cases on our developer forum instead: http://forums.autodesk.com/t5/Inventor-Customization/bd-p/120
    If your add-in appears but is unloaded, it means that it is correctly setup but an exception occurs in the Activate method. You need to set a break point in that method and work out why it is failing by debugging your code.

  3. Hello Philippe,
    I have some questions, I have used the previous version of the “Design Patterns CP3423” and I want to upgrade my code with the new “Design Patterns CP2675” or is there a newer version?
    And what is the best practice how to handle with events in “Design Patterns CP2675” I saw there isn’t an Application member any more in the StandardAddInServer.
    Best regards, Marco

  4. Philippe Avatar
    Philippe

    Hi Marco,
    Yes Design Patterns CP2675 is the latest version. You can access the Application through “addInSiteObject.Application”.
    addInSiteObject is passed to the Activate method of your addin.
    Let me know if you have any further questions on that topic.
    Regards,
    Philippe.

  5. Hello Philippe,
    The events are working, thanks.
    I have a other question about unload and reload the add-in, if I unload my add-in it unload as normal but when I want to reload the add-in again the ribbon won’t come back and when I restart Inventor the ribbon load as normal with all the buttons, I have test your “Client Graphics” add-in and I have also the same issue is this something in the add-in or PC?
    And is it possible to add the ProgressiveToolTip at the AdnButtonCommandBase in the CommandUtils?
    Regards,
    Marco.

  6. Hi Marco, I need to review the unload/reload, will let you know …
    Progressive Tooltip are not yet exposed to the API, so unfortunately no control over it.
    Philippe.

  7. Hi Philippe,
    Do have time to look at the unload/reload of the add-in?
    Marco

  8. Hi Marco, I checked in our database, unfortunately this behavior is a known issue and it hasn’t been fixed yet. You won’t be able to restore the controls from a custom add-in after unload/reload unless you reset the ribbon.
    Sorry for the bad news.

Leave a Reply to MarcoCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading