Issue with Autodesk Inventor API

Issue with Autodesk Inventor API

Anonymous
Not applicable
939 Views
5 Replies
Message 1 of 6

Issue with Autodesk Inventor API

Anonymous
Not applicable

Hello,
we have developed a windows service using C#.Net that makes use of the Autodesk Inventor Professional 2015 API. The service basically load user' requests from database, open an Autodesk Inventor Part file, set a value for each parameter, and export the model to the requested format (i.e. STEP).

The program seems to work pretty fine. Anyway, we are currently facing a strange issue: in some cases the program returns a different output when it is executed manually or executed as a windows service.
In order to exclude an issue related to windows services and account rights we have also compiled the program as a standard executable: the same program returns a different output when we execute it manually (double-click) or it is executed on a scheduled basis (using the same user account). For example, holes defined inside the model are not rendered in the proper way (some are missing and some have the wrong diameter).
We have taken a look to the knowledge base but we have not found a solution for this issue yet.

 

Do you have any idea?

 

Thanks. Best regards.

0 Likes
Accepted solutions (1)
940 Views
5 Replies
Replies (5)
Message 2 of 6

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

What Scheduler you are using to schedule the running of your program? The Windows Task Scheduler? Because that is a Windows Service too.

Also, when the Scheduler is starting your app, is the user logged in?

Is Inventor run invisibly in both cases?

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 6

matt_jlt
Collaborator
Collaborator

Do you have any more information you can provide? Theres not too much to go on. Could possibly be it's not updating correctly before it's being exported or something such as a feature is failing causing an update failure etc.

0 Likes
Message 4 of 6

Anonymous
Not applicable

 

Hello,
thanks for your answers. Originally I have registered a new windows service using the utility “InstallUtil.exe”. Anyway, to exclude a problem with windows services I have also tried to compile the program as a standard executable and I have scheduled it by means of the Windows Task Scheduler. In both cases, I have configured the service/task to use a specific account , the same I’m logged in to the computer.

I have tried to set the following properties in the program:

 

                inventorApplication.Visible = true;
                inventorApplication.WindowState = WindowsSizeEnum.kMaximize;

 

 

Anyway, the program is executed in background when it run as a service/task. I can see the Inventor console only when I manually execute the program (double-click).

When I execute it manually I can see that the model is updated correctly and no error is reported by the Inventor. Checking the program's log I can confirm that the program execute exactly the same code and set exactly the same value for parameters when run it as a service/task. Please, note that the program seems to work fine and returns the right output using other models.

Here the relevant code; I cleaned it up a bit:

 

                if (inventorApplication == null)
                {
                    Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
                    inventorApplication = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
                    inventorApplication.Visible = true;
                }
                String sourceFile = this._request.File;
                // Open CAD File
                _Document oDoc = inventorApplication.Documents.Open(this._modelDirectory + sourceFile, true);
                inventorApplication.WindowState = WindowsSizeEnum.kMaximize;
                // Retrieving active document
                PartDocument oPartDoc = (Inventor.PartDocument) inventorApplication.ActiveDocument;
                Parameters oParams = oPartDoc.ComponentDefinition.Parameters;
                // Load all parameters to model
                LoadParameterToModel(oParams, this._request.Parameters);
 
                inventorApplication.ActiveDocument.Update2(true);

                String outputFile = this._outputDirectory + fileName + "." + this._request.FileType;
                // Export to the requested format
                TranslatorSaveAs(outputFile, oDoc);

 


I have tried many different things but the result is almost the same:

- Loop over Views of the ActiveDocument and set the following properties:

 

     		v.Visible = true;
                v.WindowState = WindowsSizeEnum.kMaximize;
                v.Activate();

 

 

- Update Views of the ActiveDocument after having set parameter' values.

- Save a copy of the document, close it and reload it after having set parameter' values.

By the way, I’m running Autodesk Inventor Professional 2015 SP2.

Thanks for your support.

 

0 Likes
Message 5 of 6

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I think it might have something to do with interactivity. Some of the functionality might require desktop access / possibility of interactivity.

As you said when running your app from the Scheduler Windows Service or from your own service then Inventor cannot be made visible.

 

Two things you could try:

1) running your GUI App (that is accessing Inventor) from your Windows Service using "CreateProcessAsUser" as mentioned here https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx

2) Add "Allow service to interact with desktop" setting to your service:
https://technet.microsoft.com/en-us/library/cc782435(v=ws.10).aspx

 

I hope this helps.

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 6 of 6

Anonymous
Not applicable

 

Thank you for the useful hint. You are right, the application must always run in UserInteractive mode.

 

I was able to get it working using the approach you suggested and using this example program:

 

http://asprosys.blogspot.ch/2009/03/allow-service-to-interact-with-desktop.html

 

Thanks. Best regards.

0 Likes