Access Inventor Studio by code

By Xiaodong Liang

Inventor Studio is also an add-in of Inventor. The corresponding *.dll locates at <Inventor Installation Path>\bin\Archon.dll. This dll provides some basic interfaces of Studio. The Interop.InventorStudioLib.dll is generated by VS when you add the lib from
– 32bits: [Add Reference] >> [COM tab] >> [Inventor Studio Library ]
– 64bits: <Inventor Install Path>\bin\archon.dll  (you may need to run regsvr32 to register the dll firstly if you get a failure when adding the dll)

image

After inporting the library, you could get its Automation interface by the add-in. e.g. the code below gets the constraints names the animation uses.

using InventorStudioLib;

 

namespace WindowsFormsApplication3

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            Inventor.Application m_inventorApplication =

            (Inventor.Application)System.Runtime.InteropServices.Marshal.

            GetActiveObject("Inventor.Application");

            if (m_inventorApplication == null)

            {

                MessageBox.Show("no Inventor running!");

                return;

            }

            Inventor._Document oActivedoc = m_inventorApplication.ActiveDocument;

            if (oActivedoc == null)

            {

                MessageBox.Show("Please open an assembly document!");

                return;

            }

            //studio is also an addin which has its guid

            string sutdioAddinGuid =

            "{F3D38928-74D1-4814-8C24-A74CE8F3B2E3}";

            Inventor.ApplicationAddIn oStudioAddin = null;

            try

            {

                // try to get studio addin

                oStudioAddin =

                m_inventorApplication.ApplicationAddIns.

                get_ItemById(sutdioAddinGuid);

            }

            catch

            {

                // any error…

                return;

            }

            if (oStudioAddin != null)

            {

                // activate the addin

                if (!oStudioAddin.Activated)

                    oStudioAddin.Activate();

 

                //get property EnvironmentManager

                object oObj = oActivedoc.GetType().InvokeMember(

                "EnvironmentManager",

                System.Reflection.BindingFlags.GetProperty,

                null, oActivedoc, null, null, null, null);

                Inventor.EnvironmentManager oEnvironmentMgr =

                (Inventor.EnvironmentManager)oObj;

 

                //activate the enviroment of Studio

                Inventor.UserInterfaceManager UIManager =

                m_inventorApplication.UserInterfaceManager;

 

                if (UIManager.ActiveEnvironment.InternalName != "Archon:Env")

                {

                    Inventor.Environment studioEnv =

                    UIManager.Environments["Archon:Env"];

                    oEnvironmentMgr.SetCurrentEnvironment(studioEnv);

                }

 

                // get the automation interface of Studio

                InventorStudio oInventorStudio = oStudioAddin.Automation;

 

                //AnimationManager

                AnimationManager oAM = oInventorStudio.AnimationManager;

 

                if (oAM.AnimationFavorites.Count >0)

                {

                    MessageBox.Show("Studio has AnimationFavourites not empty");

 

                    // get first item in AnimationFavorites

                    object oAF = oAM.AnimationFavorites[1];

                    Inventor.AssemblyConstraint oAC = (Inventor.AssemblyConstraint) oAF;

                    MessageBox.Show("AnimationFavourites first item: " + oAC.Name);

                }

            }

 

        }

    }

}


Comments

One response to “Access Inventor Studio by code”

  1. KarlH Avatar
    KarlH

    Thanks for sharing Xiaodong,
    Would you happen to have any links to supporting documentation?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading