I have some code running in a C# console application that has no problems until I install the application as a service and run it that way.
I am using "Method 2" from ModTheMachine's post here: http://modthemachine.typepad.com/my_weblog/2009/01/translating-files-with-the-api.html . I am trying to export a pdf using the method described. I have also tried Method 1 from this article, in which I am trying to export a pdf using the Inventor.Document.SaveAs([filename], true) command.
As stated, the code runs fine if I manually execute the application but if I install it as a Windows Service and start it, I get a failure on the SaveAs line. Everything else runs fine.
The Inventor.Application.Visible setting is false and the Inventor.Application.SilentOperation is true in both scenarios.
Here is the error I receive:
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
Solved! Go to Solution.
Please check your source code with regards to all operations that are user specific, I mean user directories etc are different in case of a service vs.exe. Also you might have permission issues, since you are not logged in like a desktop/terminal user.
This answer is pretty common but I hope it helps either.
Andreas
Andreas,
Those are helpful suggestions but this is definitely not a permissions issue, as I am running the Service with my same user that I am logged into Windows with. I can tell through debugging that the I get a consistent error on the SaveAs line of code when I am running as a service.
I am still having this issue.
Nate
I am also having this issue. It seems that Inventor requires a visible drawing screen to actually save as or even do a plot from the printmanager object (to PDFCreator or AdobePDF). Everything works fine when it's outside the service if inventor is a visible application.
-Doug
And (as a service...not the local admin), I modified the registery to allow that user to "interact with the desktop". This had the same results.
-Doug
Check to make sure you are supplying a absolute (or full) path name for the file. Services may not started from the same directory versus just run normally so you need to make sure you're not using path names that are relative.
I appreciate the suggestion but I am definitely using a full local path as my SaveAs parameter. It's something like "C:\LocalFolder\FileName.pdf"
What i'm finding out as a difference between the service and running as a console app, is that there are a few differences, but the main ones i believe are causing the problems are:
application.ActiveView is null
and
the VisibleDocument list count is 0
If you know of a way to set an activeview or force a document visible, let me know
I am trying to set plot or save the entire assembly to a pdf (and eventually dxf or other formats)
-Doug
Document.Views.Add will make the hidden document visible.
Just to let you know that un-hidding this view this made everything work.
It's pretty nice, we have a box that runs this service, grabs parameters from a database, loads the correct assembly and generates the drawings according to specs, does this all from a web page submission.
I also have a C# console app running under a service. I'm trying to create DWF files from inventor files using the SaveCopyAs api. As you stated it works command line, but not under a service. I do get a DWF created, but it is not correct for assemblies. The view is different. For example, if I bring up the file interactively it shows a rotated view, but the dwf that gets created under the service is a "front" view.
Any idea how to make Inventor bring up the same view orientation and zoom level it would bring up interactively.
This should be a different question. To change the orientation of the document for exporting to DWF, you can make use of the View.Camera object. Below is a sample to change to view orientation:
Dim oView As View Set oView = oDoc.Views(1) Dim oCamera As Camera Set oCamera = oView.Camera oCamera.ViewOrientationType = kIsoBottomLeftViewOrientation oCamera.Apply
If you need to rotate/zoom the view, you can set the other properties in Camera, like Eye, Target, UpVector and some methods (SetExtents etc.) can help too.
hi, can you give me a simple guide how this process work? i am very interested in it. thanks
"It's pretty nice, we have a box that runs this service, grabs parameters from a database, loads the correct assembly and generates the drawings according to specs, does this all from a web page submission"
This is all inhouse code, but it goes like this...
user cycles thru silverlight designer and selects dimensions of different aspects of the object. When they are done, the server submits a list of tasks to the database and queries the database every 5 seconds (or so) waiting for a result. We have a service that monitors the database for queued jobs (this service also monitors the status of inventor, cycles a new one every so often, disables unneeded plugins, loads project files, assembly templates, associated idws, etc) and then that server (can be multiple, if needed) grabs the job and starts processing the tasks associated with it. Like set width, set depth, set height, add parts, suppress objects, etc.... all to get each task done individually. Then we load the associated IDW and call an update on the IDW document, (now we are currently saving the IDW, as some things do not get processed during an update, but do during a save) and then do a save in the proper format (pdf, dwf, and even a jpg that we use to show them on the web site).
when it's all done, the web site lets them know it's done and gives them a link to grab the file(s).
Something like that
Can't find what you're looking for? Ask the community or share your knowledge.