Run Inventor View instead normal Inventor

Run Inventor View instead normal Inventor

Anonymous
Not applicable
730 Views
3 Replies
Message 1 of 4

Run Inventor View instead normal Inventor

Anonymous
Not applicable

Dear member,

 

I'm trying to make a simple program in c# to open and close document in Inventor.

So far everything is run perfect with normal inventor. Instead of opening/viewing the Drawing in Inventor that take times to load (im using low spec laptop) i want my program to open the drawing in Inventor View that installed on my laptop because it lighter and faster. and the problem is i don't know the code to run Inventor view instance.

 

what i've tried so far

adding COM reference InventorApprentice  still can't find the object to run Inventor View

 

this is the code i used to run Inventor from my windows from

 private void button1_Click(object sender, EventArgs e)
        {
            Inventor.Application inventorApp = null; // object
            // it is not possible to write InventorApprentice.Application
            try
            {
                try
                {
                    inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                    inventorApp.Visible = true;
                }
                catch
                {
                    // Start Inventor.
                    System.Type oType = System.Type.GetTypeFromProgID("Inventor.Application");
                    MessageBox.Show("Starting Inventor. This may take afew minutes");
                    inventorApp = (Inventor.Application)System.Activator.CreateInstance(oType);

                    // Make Inventor visible.
                    inventorApp.Visible = true;
                    //inventorApp.Documents.Open; open file 
                }

            }

i hope you can help me to make my windows form to run INventor View instead of normal Inventor 

0 Likes
Accepted solutions (1)
731 Views
3 Replies
Replies (3)
Message 2 of 4

YuhanZhang
Autodesk
Autodesk
Accepted solution

The Inventor View is Apprentice-based application, it has no APIs exposed for itself, so you can't use it using API. But you can create your own viewer using Apprentice if you just want to view the Inventor data. Below is C# code snippet to show how to use the CientViews from Apprentice, you should place a PictureBox first:

            ApprenticeServerComponent oApp = null;
            oApp = new ApprenticeServerComponentClass();

            ApprenticeServerDocument oDoc = null;
            string strFile = @"C:\TEMP\MyData.ipt";
            oDoc = oApp.Open(strFile );

            ClientViews oClientViews = oDoc.ClientViews;
 
            IntPtr ptrHandle = this.pictureBox1.Handle;
            int intHandle = ptrHandle.ToInt32();
            ClientView oClientView = oClientViews.Add(intHandle);

            Camera oCam = oClientView.Camera;
            oCam.Fit();
            oCam.Apply();
            oClientView.Update(true);

Hope it helps.

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 4

Anonymous
Not applicable

thank you, i tried your solution and it worked!

since I'm using 64 bit system, I need to add this in my code otherwise it won't worked

 

 public void AddInventorPath()
        {
            // Note: System.Environment.Is64BitProcess and
            // System.Environment.Is64BitProcess were
            // introduced in .NET Framework 4.0
            string path = System.Environment.GetEnvironmentVariable("PATH");

            // In case process and OS bitness match it's
            // C:\Program Files\Autodesk\Inventor 2015
            // otherwise it's
            // C:\Program Files\Autodesk\Inventor 2015\bin
            string inventorPath = oSvr.InstallPath;

            if (System.Environment.Is64BitOperatingSystem &&
                !System.Environment.Is64BitProcess)
            {
                // If you are running the app as a 32 bit process 
                // on a 64 bit OS then you'll need this
                path += ";" + inventorPath + "Bin32";
            }
            else
            {
                // Otherwise you need this
                path += ";" + inventorPath + "Bin";
            }

            System.Environment.SetEnvironmentVariable("PATH", path);
        }
0 Likes
Message 4 of 4

YuhanZhang
Autodesk
Autodesk

Correct, you can add the code to refer to x86 or x64 Apprentice according to the system, it should work well. And since Inventor 2019 we will only provide the x64 Apprentice, just let you know.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes