apprentice error

apprentice error

Anonymous
Not applicable
822 Views
6 Replies
Message 1 of 7

apprentice error

Anonymous
Not applicable

I am upgrading some code to work with Autodesk 2013 products.  My code uses the ApprenticeServer to get some information out of Inventor files.  Anyways, it worked fine with 2012, but it randomly fails on 2013. The line that is failing is the one that tries to open the file (Inventor.ApprenticeServerDrawingDocument)GlobalVar.oApprentice.Open(drawingName);

 

Any ideas?

 

foreach (string s in drawingFileList)
                {
                    Inventor.ApprenticeServerDrawingDocument drgDoc = null;
                    string drawingName = vFileList.GetFullLocalName(Path.GetFileName(s));
                    if(System.IO.File.Exists(drawingName)) Debug.WriteLine(s + " Exists");
                    else Debug.WriteLine(drawingName + " does not exist");

                    // oApprentice.Open call seems to fails sometimes on first try.
                    //  loop until file opens, to a maximum of 5 times.
                    int numTries = 0;
                    do
                    {
                        try
                        {
                            numTries++;
                            Debug.WriteLine("The last breath");
                            drgDoc = (Inventor.ApprenticeServerDrawingDocument)GlobalVar.oApprentice.Open(drawingName);
                        }
                        catch (Exception)
                        {
                            if (numTries > 5)
                            {
                                MessageBox.Show("Cannot open Drawing");
                                break;
                            }
                            drgDoc = null;
                        }
                    } while (drgDoc == null);

 

0 Likes
823 Views
6 Replies
Replies (6)
Message 2 of 7

wayne.brill
Collaborator
Collaborator

Hello,

 

Please attach a couple of files that will allow me to recreate this behavior. Also does the failure occur with files created in Inventor 2013?

 

Thanks,

Wayne Brill

Autodesk Developer Network



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 7

Anonymous
Not applicable

Here are a few files that have been acting up. They would not have been created in 2013.  Also note that they are just randomly failing, sometimes they will work, sometimes they will not.  My code will loop through a list of files to open and it never fails on the first file it opens, it is always the second or later file that fails. I will have to try to create a simpler test bed and see if I can duplicate the problem, I suspect it has something to do with the surrounding code.

0 Likes
Message 4 of 7

Anonymous
Not applicable

I see now that I am still referencing a 2012 dll  (Interop.Inventor.dll)  I can't find this file anywhere in the 2013 files. I am assuming I need to reference a different dll now, would somebody know what it would be?

0 Likes
Message 5 of 7

Anonymous
Not applicable

In a new example in the SDK, I see it is referencing Autodesk.Inventor.Interop.  So I changed it to this, but it still doesn't clear up my problem.  I guess my hunch was wrong.

0 Likes
Message 6 of 7

wayne.brill
Collaborator
Collaborator

Hi ,

 

In my test project Apprentice will open "ALQT - Drawings.idw" but always fails opening "BOQF10 (Parts).idw". This file will not open on my system using Inventor 2012 or 2013. I get an error "The database ... could not be opened". 

 

Please let me know if you have other files that open in Inventor but will not open using Apprentice.

 

Thanks,

Wayne Brill

Autodesk Developer Network

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 7

Anonymous
Not applicable

Ok, now I have a simple test program that illustrates my problem. When the user clicks the button on the form, a file open dialog box opens, and the user selects an idw file.  The program then extracts the first drawing sheet from this file and prints it to an XPS file.  The first file selected always works ok, but as soon as a second different file is selected the program crashes. Interestingly enough, if the first file is selected twice in a row, it works fine.

 

   Note that in order to run this sample code, you will need to have the DWF Writer printer driver installed on your system.  Also, if I comment out the code pertaining to the printing, my problem also goes away.

 

   Maybe somebody can spot something that I'm missing.

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Inventor;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Xml.Linq;



namespace ApprenticeTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            Inventor.ApprenticeServerComponent oApprentice = new ApprenticeServerComponent();
            Inventor.ApprenticeServerDrawingDocument drgDoc;

            string idwName = null;

            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                idwName = dlg.FileName;
            }

            drgDoc = (Inventor.ApprenticeServerDrawingDocument) oApprentice.Open(idwName);

            string xpsFileName = System.IO.Path.GetFileNameWithoutExtension(idwName);
            xpsFileName = @"C:\tempdwf\" + xpsFileName + ".DWFx";
            if (System.IO.File.Exists(xpsFileName)) System.IO.File.Delete(xpsFileName);

            Inventor.ApprenticeDrawingPrintManager pMgr;
            pMgr = (Inventor.ApprenticeDrawingPrintManager)  drgDoc.PrintManager;
            pMgr.Printer = "Autodesk DWF Writer for 2D";
            
            pMgr.SetSheetRange(1, 1);
            pMgr.PrintRange = PrintRangeEnum.kPrintSheetRange;
            pMgr.ScaleMode = Inventor.PrintScaleModeEnum.kPrintBestFitScale;
            pMgr.Orientation = PrintOrientationEnum.kLandscapeOrientation;
            pMgr.SubmitPrint();

                        
            Process.Start(xpsFileName);
             



        }
    }
}

 

0 Likes