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:
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 }
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"); } } } } }
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.
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/