Access the API of the specific version if multi releases on the machine

By Xiaodong Liang

Issue
COM API CocreateInstance is called to get inventor application. If two different Inventor versions( say 2012, 2013) are installed on the same machine. How can we the access the API of the specific version?

Solution
You need to use following workaround.

  • Make sure that there is no Inventor.exe running. This can be done using Process.GetProcessesByName

  • Start corresponding inventor.exe using Process class

  • Use GetActiveObject to get Inventor.Application from process you started. You can use Inventor.SoftwareVersion to find out which version is currently running.

private void test()    {        bool noInvProcess = true;        foreach (Process p in                Process.GetProcessesByName("Inventor"))        {            try            {                // kill the process                p.Kill();                // possibly with a timeout                 p.WaitForExit();                           }            catch (Exception ex)            {                // error                noInvProcess = false ;                break;            }                 }             if (noInvProcess)        {            // assume we want to start inventor 2013            Process.Start(@"C:Program FilesAutodeskInventor 2013BinInventor.exe");                 // wait a moment            System.Threading.Thread.Sleep(1000);                 // get the active inventor application            string progId = "Inventor.Application";            Inventor.Application m_inventorApp =                (Inventor.Application)Marshal.                 GetActiveObject(progId);                 SoftwareVersion oInvVer = m_inventorApp.SoftwareVersion;            MessageBox.Show("current running inventor is : " + oInvVer.Major);        }    }

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading