We have a function that starts inventor when the request is an Inventor request. If it's not (other CAD platforms) they have a similar function. Inventor remains open unless it crashes. If it does, or the computer is restarted, this function will open inventor and attach the process to it on the first requests that requires it.
public static void StartInventor()
{
try
{
string sName = "";
int loop = 0;
foreach (Process Proc in Process.GetProcesses())
{
if (Proc.ProcessName.Equals("Inventor"))
{
if (loop > 0)
{
DebugLog("before kill process inventor");
killInventor();
DebugLog("after kill process inventor");
}
else
{
sName = Proc.ProcessName;
loop++;
}
}
}
if (sName == "")
{
Process.Start(@"C:\Program Files\Autodesk\Inventor 2023\Bin\Inventor.exe");
bool found = false;
int count = 0;
while (!found && count < 60)
{
try
{
System.Threading.Thread.Sleep(1000);
count++;
cSE.oInventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
found = true;
}
catch
{
DebugLog("attempts to get inventor process " + count.ToString());
}
}
if (!found)
{
cSE.oInventorApp = null;
throw new Exception("Inventor start timed out");
}
}
else
{
cSE.oInventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
}
_InvapplicationEvents = cSE.oInventorApp.ApplicationEvents;
_InvassemblyEvents = cSE.oInventorApp.AssemblyEvents;
_InvmodelEvents = cSE.oInventorApp.ModelingEvents;
if (!IsINVInit)
{
_InvapplicationEvents.OnOpenDocument += oIAppEvents_OnOpenDocument;
_InvapplicationEvents.OnSaveDocument += oIAppEvents_OnSaveDocument;
_InvapplicationEvents.OnCloseDocument += oIAppEvents_OnCloseDocument;
_InvapplicationEvents.OnInitializeDocument += oIAppEvents_OnInitializeDocument;
_InvapplicationEvents.OnReady += oIAppEvents_OnReady;
_InvassemblyEvents.OnNewOccurrence += oIAssemblyEvents_OnNewOccurrence;
_InvassemblyEvents.OnOccurrenceChange += oIAssemblyEvents_OnOccurrenceChange;
_InvassemblyEvents.OnAssemblyChange += oIAssemblyEvents_OnAssemblyChange;
_InvassemblyEvents.OnAssemblyChanged += oIAssemblyEvents_OnAssemblyChanged;
_InvmodelEvents.OnNewFeature += oIModelEvents_OnNewFeature;
IsINVInit = true;
}
//if (cFG.cServer == "DEV")
//{
//}
cSE.oInventorApp.Visible = true;
cSE.oInventorApp.WindowState = kMaximize;
cSE.oInventorApp.SilentOperation = true;
cSE.oIDocs = cSE.oInventorApp.Documents;
cSE.oITransGeo = cSE.oInventorApp.TransientGeometry;
cSE.oITransObj = cSE.oInventorApp.TransientObjects;
}
catch (Exception ex)
{
ErrorLog(ex);
throw (ex);
}
}