Inventor Customization

Reply
Member
nstuller
Posts: 4
Registered: ‎06-22-2011
Message 1 of 14 (1,405 Views)
Accepted Solution

C# Code is not working when running as a Windows Service

1405 Views, 13 Replies
06-22-2011 10:55 AM

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))

Active Contributor
ConfigurationGenius
Posts: 44
Registered: ‎08-07-2007
Message 2 of 14 (1,378 Views)

Re: C# Code is not working when running as a Windows Service

06-25-2011 12:20 AM in reply to: nstuller

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

Member
nstuller
Posts: 4
Registered: ‎06-22-2011
Message 3 of 14 (1,366 Views)

Re: C# Code is not working when running as a Windows Service

06-27-2011 01:09 PM in reply to: ConfigurationGenius

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

Active Contributor
dgesler
Posts: 30
Registered: ‎06-28-2011
Message 4 of 14 (1,353 Views)

Re: C# Code is not working when running as a Windows Service

06-28-2011 06:29 AM in reply to: nstuller

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

Active Contributor
dgesler
Posts: 30
Registered: ‎06-28-2011
Message 5 of 14 (1,351 Views)

Re: C# Code is not working when running as a Windows Service

06-28-2011 06:32 AM in reply to: dgesler

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

Valued Mentor
rjay75
Posts: 291
Registered: ‎04-14-2005
Message 6 of 14 (1,340 Views)

Re: C# Code is not working when running as a Windows Service

06-29-2011 01:50 PM in reply to: nstuller

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.

Member
nstuller
Posts: 4
Registered: ‎06-22-2011
Message 7 of 14 (1,329 Views)

Re: C# Code is not working when running as a Windows Service

06-30-2011 06:27 AM in reply to: rjay75

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"

 

Active Contributor
dgesler
Posts: 30
Registered: ‎06-28-2011
Message 8 of 14 (1,327 Views)

Re: C# Code is not working when running as a Windows Service

06-30-2011 07:03 AM in reply to: rjay75

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

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 9 of 14 (1,320 Views)

Re: C# Code is not working when running as a Windows Service

06-30-2011 08:02 PM in reply to: dgesler

Document.Views.Add will make the hidden document visible.



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Active Contributor
dgesler
Posts: 30
Registered: ‎06-28-2011
Message 10 of 14 (1,289 Views)

Re: C# Code is not working when running as a Windows Service

07-25-2011 06:43 AM in reply to: yuhanzhang

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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube