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.