Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Beginning Inventor API Programming

5 REPLIES 5
Reply
Message 1 of 6
btillman
3987 Views, 5 Replies

Beginning Inventor API Programming

I've spent the last several years developing .NET programs which allow a user with no experience at all with AutoCAD to get drawings and BOMs by using a web interface. I've now taken on a similar task but this time I'll be using Inventor instead of AutoCAD and after my first day into the plan I can report these findings:

 

  1. I was surprised to find that almost all the tutorials and examples for using the Inventor API use VB, not my languages of choice C# and Python.
  2. The tutorials available are usually old and outdated. I think most of you will agree that there seems to be a conspiracy among AutoDesk developers to change up everything from one release to the next. What worked in 2015, no longer works for 2017.
  3. The work I'm interested in will be where the Inventor software will never be visible to the users. In fact, it will be running on a machine that will probably not even be in the same building with them. Their requests will be formatted and the drawings and BOMs will be prepared and stored for them to access either by email or a link to another server, in PDF format. Remember, the users I'm targeting have no idea how to use Inventor or even that Inventor is driving the process.
  4. The tutorials I've studied thus far rely heavily on user input, or a file already existing is to be modified in some manner. Again, the target for this platform are people with no experience or desire to learn Inventor or any other software. They will simply be clicking on options in their web browser. The ability to produce accurate and speedy documents while being as hands-free as possible is the main goal.

Okay, that said, I'm looking first to have my C# code check if an instance of Inventor is running and if so use it. If not, open one and use it. Thus far all I've found is code which will report to the user if an instance is found or not. Again, this project will not be interested in reporting anything to the users except that their drawing/BOM is complete.

 

Here is the very simple start of my project:

 

try
{
Inventor.Application objApp = null;
objApp = (Inventor.Application)
System.Runtime.InteropServices.Marshal.GetActiveObject
("Inventor.Application"); } catch { // This is where I need to start Inventor running if an instance is not found }

 

5 REPLIES 5
Message 2 of 6
btillman
in reply to: btillman

I know this is like watching paint dry but here is where I've got it so far. I'm tryin to convert the code shown in this article to C#. Also, since this is a "no user interface allowed" project I'm using a console app instead of a Windows Form Application. And I'd like to have the code to gracefully shutdown Inventor when this app has completed like they show in the article because while this will open Inventor, when you close it down I'm left with the instance still in the Task Manager.

 

using System;
using System.Runtime.InteropServices;
using Inventor;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Inventor.Application _invApp;
            Boolean _started = false;

            try
            {
                _invApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch (Exception ex)
            {
                try
                {
                    Type invAppType = Type.GetTypeFromProgID("Inventor.Application");
                    _invApp = (Inventor.Application)Activator.CreateInstance(invAppType);
                    _invApp.Visible = true;
                    _started = true;

                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.ToString());
                    Console.WriteLine("Unable to get or start Inventor");
                }
            }

        }
    }
}

 

Message 3 of 6
rikard.nilsson
in reply to: btillman

Hi,

If you want to close the process you use the process.Kill().
You will find a lot of help if you google it.

/Rikard
Message 4 of 6
btillman
in reply to: rikard.nilsson

Cool, some perseverance and I've got a simple class to launch Inventor and close it down safely with nothing left in the Task Manager. Now comes the hard part of making the rest of it meet the client's requirements.

 

There was something I recall about the AutoCAD project I worked on a little while back. As lots of the objects in the AutoCAD files were created by LISP it was necessary to have the instance of AutoCAD visible on the monitor. In fact, some of the trimming and copying operations would not work at all unless the resolution of the monitor was just right. I was hoping that most of the tasks I'll be doing for this project will be do-able without needing the screen to have the image on-line.

Message 5 of 6
rikard.nilsson
in reply to: btillman

Hi,

If I remember this right.
Most of the stuff you do will work with a non visible application. But when it comes to export like a PDF from a drawing it might need to be visible.
Good luck!

/Rikard
Message 6 of 6
Owner2229
in reply to: btillman

Hey, there's no need for Inventor to be visible for any kind of operations.

For the start, to run Inventor invisible set this to false:

_invApp.Visible = false;

Also, for simple tasks I would suggest you looking at the Inventor Apprentice Server.

It's a lot faster than Inventor, but it has some limits. The plus is also it has nearly zero start up time.

It can e.g.:

Open part/assembly/drawing/...

Export PDF/DWG/DXF/STEP...

Update documents

Update part refferences

 

It can't e.g:

Change model geometry

Replace part/assy occurences in parts/assemblies

Create/Migrate documents

 

You can also use the combination of these two. Inventor for construction work and (faster) Apprentice for updating and exporting on demand.

 

Here you can get some code samples for C#, but I would suggest you either looking into VB programming or converting the VB samples:

modthemachine.typepad.com/my_weblog/c/

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report